id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
10,600
|
gitblit/fathom
|
fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java
|
SwaggerBuilder.getControllerTag
|
protected Tag getControllerTag(Class<? extends Controller> controllerClass) {
if (controllerClass.isAnnotationPresent(ApiOperations.class)) {
ApiOperations annotation = controllerClass.getAnnotation(ApiOperations.class);
io.swagger.models.Tag tag = new io.swagger.models.Tag();
tag.setName(Optional.fromNullable(Strings.emptyToNull(annotation.tag())).or(controllerClass.getSimpleName()));
tag.setDescription(translate(annotation.descriptionKey(), annotation.description()));
if (!Strings.isNullOrEmpty(annotation.externalDocs())) {
ExternalDocs docs = new ExternalDocs();
docs.setUrl(annotation.externalDocs());
tag.setExternalDocs(docs);
}
if (!Strings.isNullOrEmpty(tag.getDescription())) {
return tag;
}
}
return null;
}
|
java
|
protected Tag getControllerTag(Class<? extends Controller> controllerClass) {
if (controllerClass.isAnnotationPresent(ApiOperations.class)) {
ApiOperations annotation = controllerClass.getAnnotation(ApiOperations.class);
io.swagger.models.Tag tag = new io.swagger.models.Tag();
tag.setName(Optional.fromNullable(Strings.emptyToNull(annotation.tag())).or(controllerClass.getSimpleName()));
tag.setDescription(translate(annotation.descriptionKey(), annotation.description()));
if (!Strings.isNullOrEmpty(annotation.externalDocs())) {
ExternalDocs docs = new ExternalDocs();
docs.setUrl(annotation.externalDocs());
tag.setExternalDocs(docs);
}
if (!Strings.isNullOrEmpty(tag.getDescription())) {
return tag;
}
}
return null;
}
|
[
"protected",
"Tag",
"getControllerTag",
"(",
"Class",
"<",
"?",
"extends",
"Controller",
">",
"controllerClass",
")",
"{",
"if",
"(",
"controllerClass",
".",
"isAnnotationPresent",
"(",
"ApiOperations",
".",
"class",
")",
")",
"{",
"ApiOperations",
"annotation",
"=",
"controllerClass",
".",
"getAnnotation",
"(",
"ApiOperations",
".",
"class",
")",
";",
"io",
".",
"swagger",
".",
"models",
".",
"Tag",
"tag",
"=",
"new",
"io",
".",
"swagger",
".",
"models",
".",
"Tag",
"(",
")",
";",
"tag",
".",
"setName",
"(",
"Optional",
".",
"fromNullable",
"(",
"Strings",
".",
"emptyToNull",
"(",
"annotation",
".",
"tag",
"(",
")",
")",
")",
".",
"or",
"(",
"controllerClass",
".",
"getSimpleName",
"(",
")",
")",
")",
";",
"tag",
".",
"setDescription",
"(",
"translate",
"(",
"annotation",
".",
"descriptionKey",
"(",
")",
",",
"annotation",
".",
"description",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"Strings",
".",
"isNullOrEmpty",
"(",
"annotation",
".",
"externalDocs",
"(",
")",
")",
")",
"{",
"ExternalDocs",
"docs",
"=",
"new",
"ExternalDocs",
"(",
")",
";",
"docs",
".",
"setUrl",
"(",
"annotation",
".",
"externalDocs",
"(",
")",
")",
";",
"tag",
".",
"setExternalDocs",
"(",
"docs",
")",
";",
"}",
"if",
"(",
"!",
"Strings",
".",
"isNullOrEmpty",
"(",
"tag",
".",
"getDescription",
"(",
")",
")",
")",
"{",
"return",
"tag",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the Tag for a controller.
@param controllerClass
@return a controller tag or null
|
[
"Returns",
"the",
"Tag",
"for",
"a",
"controller",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java#L946-L964
|
10,601
|
gitblit/fathom
|
fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java
|
SwaggerBuilder.getModelTag
|
protected Tag getModelTag(Class<?> modelClass) {
if (modelClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = modelClass.getAnnotation(ApiModel.class);
Tag tag = new Tag();
tag.setName(Optional.fromNullable(Strings.emptyToNull(annotation.name())).or(modelClass.getSimpleName()));
tag.setDescription(translate(annotation.descriptionKey(), annotation.description()));
return tag;
}
Tag tag = new Tag();
tag.setName(modelClass.getName());
return tag;
}
|
java
|
protected Tag getModelTag(Class<?> modelClass) {
if (modelClass.isAnnotationPresent(ApiModel.class)) {
ApiModel annotation = modelClass.getAnnotation(ApiModel.class);
Tag tag = new Tag();
tag.setName(Optional.fromNullable(Strings.emptyToNull(annotation.name())).or(modelClass.getSimpleName()));
tag.setDescription(translate(annotation.descriptionKey(), annotation.description()));
return tag;
}
Tag tag = new Tag();
tag.setName(modelClass.getName());
return tag;
}
|
[
"protected",
"Tag",
"getModelTag",
"(",
"Class",
"<",
"?",
">",
"modelClass",
")",
"{",
"if",
"(",
"modelClass",
".",
"isAnnotationPresent",
"(",
"ApiModel",
".",
"class",
")",
")",
"{",
"ApiModel",
"annotation",
"=",
"modelClass",
".",
"getAnnotation",
"(",
"ApiModel",
".",
"class",
")",
";",
"Tag",
"tag",
"=",
"new",
"Tag",
"(",
")",
";",
"tag",
".",
"setName",
"(",
"Optional",
".",
"fromNullable",
"(",
"Strings",
".",
"emptyToNull",
"(",
"annotation",
".",
"name",
"(",
")",
")",
")",
".",
"or",
"(",
"modelClass",
".",
"getSimpleName",
"(",
")",
")",
")",
";",
"tag",
".",
"setDescription",
"(",
"translate",
"(",
"annotation",
".",
"descriptionKey",
"(",
")",
",",
"annotation",
".",
"description",
"(",
")",
")",
")",
";",
"return",
"tag",
";",
"}",
"Tag",
"tag",
"=",
"new",
"Tag",
"(",
")",
";",
"tag",
".",
"setName",
"(",
"modelClass",
".",
"getName",
"(",
")",
")",
";",
"return",
"tag",
";",
"}"
] |
Returns the tag of the model.
This ref is either explicitly named or it is generated from the model class name.
@param modelClass
@return the tag of the model
|
[
"Returns",
"the",
"tag",
"of",
"the",
"model",
".",
"This",
"ref",
"is",
"either",
"explicitly",
"named",
"or",
"it",
"is",
"generated",
"from",
"the",
"model",
"class",
"name",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java#L973-L985
|
10,602
|
gitblit/fathom
|
fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java
|
SwaggerBuilder.getDescription
|
protected String getDescription(Parameter parameter) {
if (parameter.isAnnotationPresent(Desc.class)) {
Desc annotation = parameter.getAnnotation(Desc.class);
return translate(annotation.key(), annotation.value());
}
return null;
}
|
java
|
protected String getDescription(Parameter parameter) {
if (parameter.isAnnotationPresent(Desc.class)) {
Desc annotation = parameter.getAnnotation(Desc.class);
return translate(annotation.key(), annotation.value());
}
return null;
}
|
[
"protected",
"String",
"getDescription",
"(",
"Parameter",
"parameter",
")",
"{",
"if",
"(",
"parameter",
".",
"isAnnotationPresent",
"(",
"Desc",
".",
"class",
")",
")",
"{",
"Desc",
"annotation",
"=",
"parameter",
".",
"getAnnotation",
"(",
"Desc",
".",
"class",
")",
";",
"return",
"translate",
"(",
"annotation",
".",
"key",
"(",
")",
",",
"annotation",
".",
"value",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the description of a parameter.
@param parameter
@return the parameter description
|
[
"Returns",
"the",
"description",
"of",
"a",
"parameter",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java#L1017-L1023
|
10,603
|
gitblit/fathom
|
fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java
|
SwaggerBuilder.isRequired
|
protected boolean isRequired(Parameter parameter) {
return parameter.isAnnotationPresent(Body.class)
|| parameter.isAnnotationPresent(Required.class)
|| parameter.isAnnotationPresent(NotNull.class);
}
|
java
|
protected boolean isRequired(Parameter parameter) {
return parameter.isAnnotationPresent(Body.class)
|| parameter.isAnnotationPresent(Required.class)
|| parameter.isAnnotationPresent(NotNull.class);
}
|
[
"protected",
"boolean",
"isRequired",
"(",
"Parameter",
"parameter",
")",
"{",
"return",
"parameter",
".",
"isAnnotationPresent",
"(",
"Body",
".",
"class",
")",
"||",
"parameter",
".",
"isAnnotationPresent",
"(",
"Required",
".",
"class",
")",
"||",
"parameter",
".",
"isAnnotationPresent",
"(",
"NotNull",
".",
"class",
")",
";",
"}"
] |
Determines if a parameter is Required or not.
@param parameter
@return true if the parameter is required
|
[
"Determines",
"if",
"a",
"parameter",
"is",
"Required",
"or",
"not",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java#L1031-L1035
|
10,604
|
gitblit/fathom
|
fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java
|
SwaggerBuilder.translate
|
protected String translate(String messageKey, String defaultMessage) {
if (messages == null || Strings.isNullOrEmpty(messageKey)) {
return Strings.emptyToNull(defaultMessage);
}
return Strings.emptyToNull(messages.getWithDefault(messageKey, defaultMessage, defaultLanguage));
}
|
java
|
protected String translate(String messageKey, String defaultMessage) {
if (messages == null || Strings.isNullOrEmpty(messageKey)) {
return Strings.emptyToNull(defaultMessage);
}
return Strings.emptyToNull(messages.getWithDefault(messageKey, defaultMessage, defaultLanguage));
}
|
[
"protected",
"String",
"translate",
"(",
"String",
"messageKey",
",",
"String",
"defaultMessage",
")",
"{",
"if",
"(",
"messages",
"==",
"null",
"||",
"Strings",
".",
"isNullOrEmpty",
"(",
"messageKey",
")",
")",
"{",
"return",
"Strings",
".",
"emptyToNull",
"(",
"defaultMessage",
")",
";",
"}",
"return",
"Strings",
".",
"emptyToNull",
"(",
"messages",
".",
"getWithDefault",
"(",
"messageKey",
",",
"defaultMessage",
",",
"defaultLanguage",
")",
")",
";",
"}"
] |
Attempts to provide a localized message.
@param messageKey
@param defaultMessage
@return the default message or a localized message or null
|
[
"Attempts",
"to",
"provide",
"a",
"localized",
"message",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest-swagger/src/main/java/fathom/rest/swagger/SwaggerBuilder.java#L1083-L1088
|
10,605
|
gitblit/fathom
|
fathom-rest/src/main/java/fathom/rest/controller/ControllerRegistrar.java
|
ControllerRegistrar.init
|
public final void init(String... packageNames) {
Collection<Class<?>> classes = discoverClasses(packageNames);
if (classes.isEmpty()) {
log.warn("No annotated controllers found in package(s) '{}'", Arrays.toString(packageNames));
return;
}
log.debug("Found {} controller classes in {} package(s)", classes.size(), packageNames.length);
init(classes);
}
|
java
|
public final void init(String... packageNames) {
Collection<Class<?>> classes = discoverClasses(packageNames);
if (classes.isEmpty()) {
log.warn("No annotated controllers found in package(s) '{}'", Arrays.toString(packageNames));
return;
}
log.debug("Found {} controller classes in {} package(s)", classes.size(), packageNames.length);
init(classes);
}
|
[
"public",
"final",
"void",
"init",
"(",
"String",
"...",
"packageNames",
")",
"{",
"Collection",
"<",
"Class",
"<",
"?",
">",
">",
"classes",
"=",
"discoverClasses",
"(",
"packageNames",
")",
";",
"if",
"(",
"classes",
".",
"isEmpty",
"(",
")",
")",
"{",
"log",
".",
"warn",
"(",
"\"No annotated controllers found in package(s) '{}'\"",
",",
"Arrays",
".",
"toString",
"(",
"packageNames",
")",
")",
";",
"return",
";",
"}",
"log",
".",
"debug",
"(",
"\"Found {} controller classes in {} package(s)\"",
",",
"classes",
".",
"size",
"(",
")",
",",
"packageNames",
".",
"length",
")",
";",
"init",
"(",
"classes",
")",
";",
"}"
] |
Scans, identifies, and registers annotated controller methods for the
current runtime settings.
@param packageNames
|
[
"Scans",
"identifies",
"and",
"registers",
"annotated",
"controller",
"methods",
"for",
"the",
"current",
"runtime",
"settings",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest/src/main/java/fathom/rest/controller/ControllerRegistrar.java#L72-L83
|
10,606
|
gitblit/fathom
|
fathom-rest/src/main/java/fathom/rest/controller/ControllerRegistrar.java
|
ControllerRegistrar.init
|
public final void init(Class<? extends Controller>... controllers) {
List<Class<?>> classes = Arrays.asList(controllers);
init(classes);
}
|
java
|
public final void init(Class<? extends Controller>... controllers) {
List<Class<?>> classes = Arrays.asList(controllers);
init(classes);
}
|
[
"public",
"final",
"void",
"init",
"(",
"Class",
"<",
"?",
"extends",
"Controller",
">",
"...",
"controllers",
")",
"{",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"classes",
"=",
"Arrays",
".",
"asList",
"(",
"controllers",
")",
";",
"init",
"(",
"classes",
")",
";",
"}"
] |
Register all methods in the specified controller classes.
@param controllers
|
[
"Register",
"all",
"methods",
"in",
"the",
"specified",
"controller",
"classes",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest/src/main/java/fathom/rest/controller/ControllerRegistrar.java#L90-L93
|
10,607
|
gitblit/fathom
|
fathom-rest/src/main/java/fathom/rest/controller/ControllerRegistrar.java
|
ControllerRegistrar.registerControllerMethods
|
private void registerControllerMethods(Map<Method, Class<? extends Annotation>> discoveredMethods) {
Collection<Method> methods = sortMethods(discoveredMethods.keySet());
Map<Class<? extends Controller>, Set<String>> controllers = new HashMap<>();
for (Method method : methods) {
Class<? extends Controller> controllerClass = (Class<? extends Controller>) method.getDeclaringClass();
if (!controllers.containsKey(controllerClass)) {
Set<String> paths = collectPaths(controllerClass);
controllers.put(controllerClass, paths);
}
Class<? extends Annotation> httpMethodAnnotationClass = discoveredMethods.get(method);
Annotation httpMethodAnnotation = method.getAnnotation(httpMethodAnnotationClass);
String httpMethod = httpMethodAnnotation.annotationType().getAnnotation(HttpMethod.class).value();
String[] methodPaths = ClassUtil.executeDeclaredMethod(httpMethodAnnotation, "value");
Set<String> controllerPaths = controllers.get(controllerClass);
if (controllerPaths.isEmpty()) {
// add an empty string to allow controllerPaths iteration
controllerPaths.add("");
}
for (String controllerPath : controllerPaths) {
if (methodPaths.length == 0) {
// method does not specify a path, inherit from controller
String fullPath = StringUtils.addStart(StringUtils.removeEnd(controllerPath, "/"), "/");
ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName());
handler.validateMethodArgs(fullPath);
RouteRegistration registration = new RouteRegistration(httpMethod, fullPath, handler);
configureRegistration(registration, method);
routeRegistrations.add(registration);
} else {
// method specifies one or more paths, concatenate with controller paths
for (String methodPath : methodPaths) {
String path = Joiner.on("/").skipNulls().join(StringUtils.removeEnd(controllerPath, "/"), StringUtils.removeStart(methodPath, "/"));
String fullPath = StringUtils.addStart(StringUtils.removeEnd(path, "/"), "/");
ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName());
handler.validateMethodArgs(fullPath);
RouteRegistration registration = new RouteRegistration(httpMethod, fullPath, handler);
configureRegistration(registration, method);
routeRegistrations.add(registration);
}
}
}
}
}
|
java
|
private void registerControllerMethods(Map<Method, Class<? extends Annotation>> discoveredMethods) {
Collection<Method> methods = sortMethods(discoveredMethods.keySet());
Map<Class<? extends Controller>, Set<String>> controllers = new HashMap<>();
for (Method method : methods) {
Class<? extends Controller> controllerClass = (Class<? extends Controller>) method.getDeclaringClass();
if (!controllers.containsKey(controllerClass)) {
Set<String> paths = collectPaths(controllerClass);
controllers.put(controllerClass, paths);
}
Class<? extends Annotation> httpMethodAnnotationClass = discoveredMethods.get(method);
Annotation httpMethodAnnotation = method.getAnnotation(httpMethodAnnotationClass);
String httpMethod = httpMethodAnnotation.annotationType().getAnnotation(HttpMethod.class).value();
String[] methodPaths = ClassUtil.executeDeclaredMethod(httpMethodAnnotation, "value");
Set<String> controllerPaths = controllers.get(controllerClass);
if (controllerPaths.isEmpty()) {
// add an empty string to allow controllerPaths iteration
controllerPaths.add("");
}
for (String controllerPath : controllerPaths) {
if (methodPaths.length == 0) {
// method does not specify a path, inherit from controller
String fullPath = StringUtils.addStart(StringUtils.removeEnd(controllerPath, "/"), "/");
ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName());
handler.validateMethodArgs(fullPath);
RouteRegistration registration = new RouteRegistration(httpMethod, fullPath, handler);
configureRegistration(registration, method);
routeRegistrations.add(registration);
} else {
// method specifies one or more paths, concatenate with controller paths
for (String methodPath : methodPaths) {
String path = Joiner.on("/").skipNulls().join(StringUtils.removeEnd(controllerPath, "/"), StringUtils.removeStart(methodPath, "/"));
String fullPath = StringUtils.addStart(StringUtils.removeEnd(path, "/"), "/");
ControllerHandler handler = new ControllerHandler(injector, controllerClass, method.getName());
handler.validateMethodArgs(fullPath);
RouteRegistration registration = new RouteRegistration(httpMethod, fullPath, handler);
configureRegistration(registration, method);
routeRegistrations.add(registration);
}
}
}
}
}
|
[
"private",
"void",
"registerControllerMethods",
"(",
"Map",
"<",
"Method",
",",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
">",
"discoveredMethods",
")",
"{",
"Collection",
"<",
"Method",
">",
"methods",
"=",
"sortMethods",
"(",
"discoveredMethods",
".",
"keySet",
"(",
")",
")",
";",
"Map",
"<",
"Class",
"<",
"?",
"extends",
"Controller",
">",
",",
"Set",
"<",
"String",
">",
">",
"controllers",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"Method",
"method",
":",
"methods",
")",
"{",
"Class",
"<",
"?",
"extends",
"Controller",
">",
"controllerClass",
"=",
"(",
"Class",
"<",
"?",
"extends",
"Controller",
">",
")",
"method",
".",
"getDeclaringClass",
"(",
")",
";",
"if",
"(",
"!",
"controllers",
".",
"containsKey",
"(",
"controllerClass",
")",
")",
"{",
"Set",
"<",
"String",
">",
"paths",
"=",
"collectPaths",
"(",
"controllerClass",
")",
";",
"controllers",
".",
"put",
"(",
"controllerClass",
",",
"paths",
")",
";",
"}",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
"httpMethodAnnotationClass",
"=",
"discoveredMethods",
".",
"get",
"(",
"method",
")",
";",
"Annotation",
"httpMethodAnnotation",
"=",
"method",
".",
"getAnnotation",
"(",
"httpMethodAnnotationClass",
")",
";",
"String",
"httpMethod",
"=",
"httpMethodAnnotation",
".",
"annotationType",
"(",
")",
".",
"getAnnotation",
"(",
"HttpMethod",
".",
"class",
")",
".",
"value",
"(",
")",
";",
"String",
"[",
"]",
"methodPaths",
"=",
"ClassUtil",
".",
"executeDeclaredMethod",
"(",
"httpMethodAnnotation",
",",
"\"value\"",
")",
";",
"Set",
"<",
"String",
">",
"controllerPaths",
"=",
"controllers",
".",
"get",
"(",
"controllerClass",
")",
";",
"if",
"(",
"controllerPaths",
".",
"isEmpty",
"(",
")",
")",
"{",
"// add an empty string to allow controllerPaths iteration",
"controllerPaths",
".",
"add",
"(",
"\"\"",
")",
";",
"}",
"for",
"(",
"String",
"controllerPath",
":",
"controllerPaths",
")",
"{",
"if",
"(",
"methodPaths",
".",
"length",
"==",
"0",
")",
"{",
"// method does not specify a path, inherit from controller",
"String",
"fullPath",
"=",
"StringUtils",
".",
"addStart",
"(",
"StringUtils",
".",
"removeEnd",
"(",
"controllerPath",
",",
"\"/\"",
")",
",",
"\"/\"",
")",
";",
"ControllerHandler",
"handler",
"=",
"new",
"ControllerHandler",
"(",
"injector",
",",
"controllerClass",
",",
"method",
".",
"getName",
"(",
")",
")",
";",
"handler",
".",
"validateMethodArgs",
"(",
"fullPath",
")",
";",
"RouteRegistration",
"registration",
"=",
"new",
"RouteRegistration",
"(",
"httpMethod",
",",
"fullPath",
",",
"handler",
")",
";",
"configureRegistration",
"(",
"registration",
",",
"method",
")",
";",
"routeRegistrations",
".",
"add",
"(",
"registration",
")",
";",
"}",
"else",
"{",
"// method specifies one or more paths, concatenate with controller paths",
"for",
"(",
"String",
"methodPath",
":",
"methodPaths",
")",
"{",
"String",
"path",
"=",
"Joiner",
".",
"on",
"(",
"\"/\"",
")",
".",
"skipNulls",
"(",
")",
".",
"join",
"(",
"StringUtils",
".",
"removeEnd",
"(",
"controllerPath",
",",
"\"/\"",
")",
",",
"StringUtils",
".",
"removeStart",
"(",
"methodPath",
",",
"\"/\"",
")",
")",
";",
"String",
"fullPath",
"=",
"StringUtils",
".",
"addStart",
"(",
"StringUtils",
".",
"removeEnd",
"(",
"path",
",",
"\"/\"",
")",
",",
"\"/\"",
")",
";",
"ControllerHandler",
"handler",
"=",
"new",
"ControllerHandler",
"(",
"injector",
",",
"controllerClass",
",",
"method",
".",
"getName",
"(",
")",
")",
";",
"handler",
".",
"validateMethodArgs",
"(",
"fullPath",
")",
";",
"RouteRegistration",
"registration",
"=",
"new",
"RouteRegistration",
"(",
"httpMethod",
",",
"fullPath",
",",
"handler",
")",
";",
"configureRegistration",
"(",
"registration",
",",
"method",
")",
";",
"routeRegistrations",
".",
"add",
"(",
"registration",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Register the controller methods as Routes.
@param discoveredMethods
|
[
"Register",
"the",
"controller",
"methods",
"as",
"Routes",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest/src/main/java/fathom/rest/controller/ControllerRegistrar.java#L124-L177
|
10,608
|
gitblit/fathom
|
fathom-mailer/src/main/java/fathom/mailer/Mailer.java
|
Mailer.newTextMailRequest
|
public MailRequest newTextMailRequest(String subject, String body) {
return createMailRequest(generateRequestId(), false, subject, body);
}
|
java
|
public MailRequest newTextMailRequest(String subject, String body) {
return createMailRequest(generateRequestId(), false, subject, body);
}
|
[
"public",
"MailRequest",
"newTextMailRequest",
"(",
"String",
"subject",
",",
"String",
"body",
")",
"{",
"return",
"createMailRequest",
"(",
"generateRequestId",
"(",
")",
",",
"false",
",",
"subject",
",",
"body",
")",
";",
"}"
] |
Creates a plain text MailRequest with the specified subject and body.
A request id is automatically generated.
@param subject
@param body
@return a text mail request
|
[
"Creates",
"a",
"plain",
"text",
"MailRequest",
"with",
"the",
"specified",
"subject",
"and",
"body",
".",
"A",
"request",
"id",
"is",
"automatically",
"generated",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-mailer/src/main/java/fathom/mailer/Mailer.java#L97-L99
|
10,609
|
gitblit/fathom
|
fathom-mailer/src/main/java/fathom/mailer/Mailer.java
|
Mailer.newTextMailRequest
|
public MailRequest newTextMailRequest(String requestId, String subject, String body) {
return createMailRequest(requestId, false, subject, body);
}
|
java
|
public MailRequest newTextMailRequest(String requestId, String subject, String body) {
return createMailRequest(requestId, false, subject, body);
}
|
[
"public",
"MailRequest",
"newTextMailRequest",
"(",
"String",
"requestId",
",",
"String",
"subject",
",",
"String",
"body",
")",
"{",
"return",
"createMailRequest",
"(",
"requestId",
",",
"false",
",",
"subject",
",",
"body",
")",
";",
"}"
] |
Creates a plan text MailRequest with the specified subject and body.
The request id is supplied.
@param requestId
@param subject
@param body
@return a text mail request
|
[
"Creates",
"a",
"plan",
"text",
"MailRequest",
"with",
"the",
"specified",
"subject",
"and",
"body",
".",
"The",
"request",
"id",
"is",
"supplied",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-mailer/src/main/java/fathom/mailer/Mailer.java#L110-L112
|
10,610
|
gitblit/fathom
|
fathom-mailer/src/main/java/fathom/mailer/Mailer.java
|
Mailer.newHtmlMailRequest
|
public MailRequest newHtmlMailRequest(String subject, String body) {
return createMailRequest(generateRequestId(), true, subject, body);
}
|
java
|
public MailRequest newHtmlMailRequest(String subject, String body) {
return createMailRequest(generateRequestId(), true, subject, body);
}
|
[
"public",
"MailRequest",
"newHtmlMailRequest",
"(",
"String",
"subject",
",",
"String",
"body",
")",
"{",
"return",
"createMailRequest",
"(",
"generateRequestId",
"(",
")",
",",
"true",
",",
"subject",
",",
"body",
")",
";",
"}"
] |
Creates an html MailRequest with the specified subject and body.
The request id is automatically generated.
@param subject
@param body
@return an html mail request
|
[
"Creates",
"an",
"html",
"MailRequest",
"with",
"the",
"specified",
"subject",
"and",
"body",
".",
"The",
"request",
"id",
"is",
"automatically",
"generated",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-mailer/src/main/java/fathom/mailer/Mailer.java#L122-L124
|
10,611
|
gitblit/fathom
|
fathom-mailer/src/main/java/fathom/mailer/Mailer.java
|
Mailer.newHtmlMailRequest
|
public MailRequest newHtmlMailRequest(String requestId, String subject, String body) {
return createMailRequest(requestId, true, subject, body);
}
|
java
|
public MailRequest newHtmlMailRequest(String requestId, String subject, String body) {
return createMailRequest(requestId, true, subject, body);
}
|
[
"public",
"MailRequest",
"newHtmlMailRequest",
"(",
"String",
"requestId",
",",
"String",
"subject",
",",
"String",
"body",
")",
"{",
"return",
"createMailRequest",
"(",
"requestId",
",",
"true",
",",
"subject",
",",
"body",
")",
";",
"}"
] |
Creates an html MailRequest with the specified subject and body.
The request id is supplied.
@param requestId
@param subject
@param body
@return an html mail request
|
[
"Creates",
"an",
"html",
"MailRequest",
"with",
"the",
"specified",
"subject",
"and",
"body",
".",
"The",
"request",
"id",
"is",
"supplied",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-mailer/src/main/java/fathom/mailer/Mailer.java#L135-L137
|
10,612
|
gitblit/fathom
|
fathom-mailer/src/main/java/fathom/mailer/Mailer.java
|
Mailer.newTextTemplateMailRequest
|
public MailRequest newTextTemplateMailRequest(String subjectTemplate, String textTemplateName, Map<String, Object> parameters) {
return createTemplateMailRequest(generateRequestId(), subjectTemplate, textTemplateName, false, parameters);
}
|
java
|
public MailRequest newTextTemplateMailRequest(String subjectTemplate, String textTemplateName, Map<String, Object> parameters) {
return createTemplateMailRequest(generateRequestId(), subjectTemplate, textTemplateName, false, parameters);
}
|
[
"public",
"MailRequest",
"newTextTemplateMailRequest",
"(",
"String",
"subjectTemplate",
",",
"String",
"textTemplateName",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"parameters",
")",
"{",
"return",
"createTemplateMailRequest",
"(",
"generateRequestId",
"(",
")",
",",
"subjectTemplate",
",",
"textTemplateName",
",",
"false",
",",
"parameters",
")",
";",
"}"
] |
Creates a MailRequest from the specified template.
The request id is automatically generated.
@param subjectTemplate a string that uses the parameters & TemplateEngine to interpolate values
@param textTemplateName the name of the classpath template resource
@param parameters
@return a text mail request
|
[
"Creates",
"a",
"MailRequest",
"from",
"the",
"specified",
"template",
".",
"The",
"request",
"id",
"is",
"automatically",
"generated",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-mailer/src/main/java/fathom/mailer/Mailer.java#L155-L157
|
10,613
|
gitblit/fathom
|
fathom-mailer/src/main/java/fathom/mailer/Mailer.java
|
Mailer.newHtmlTemplateMailRequest
|
public MailRequest newHtmlTemplateMailRequest(String requestId, String subjectTemplate, String htmlTemplateName, Map<String, Object> parameters) {
return createTemplateMailRequest(requestId, subjectTemplate, htmlTemplateName, true, parameters);
}
|
java
|
public MailRequest newHtmlTemplateMailRequest(String requestId, String subjectTemplate, String htmlTemplateName, Map<String, Object> parameters) {
return createTemplateMailRequest(requestId, subjectTemplate, htmlTemplateName, true, parameters);
}
|
[
"public",
"MailRequest",
"newHtmlTemplateMailRequest",
"(",
"String",
"requestId",
",",
"String",
"subjectTemplate",
",",
"String",
"htmlTemplateName",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"parameters",
")",
"{",
"return",
"createTemplateMailRequest",
"(",
"requestId",
",",
"subjectTemplate",
",",
"htmlTemplateName",
",",
"true",
",",
"parameters",
")",
";",
"}"
] |
Creates a MailRequest from the specified template.
The request id is supplied.
@param subjectTemplate a string that uses the parameters & TemplateEngine to interpolate values
@param htmlTemplateName the name of the classpath template resource
@param parameters
@return an html mail request
|
[
"Creates",
"a",
"MailRequest",
"from",
"the",
"specified",
"template",
".",
"The",
"request",
"id",
"is",
"supplied",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-mailer/src/main/java/fathom/mailer/Mailer.java#L194-L196
|
10,614
|
gitblit/fathom
|
fathom-rest/src/main/java/fathom/rest/RestModule.java
|
RestModule.getPippoSettings
|
public static PippoSettings getPippoSettings(Settings settings) {
RuntimeMode runtimeMode = RuntimeMode.PROD;
for (RuntimeMode mode : RuntimeMode.values()) {
if (mode.name().equalsIgnoreCase(settings.getMode().toString())) {
runtimeMode = mode;
}
}
final Properties properties = settings.toProperties();
final PippoSettings pippoSettings = new PippoSettings(runtimeMode);
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Object value = entry.getValue();
String propertyValue;
if (value instanceof Collection) {
// strip brackets from collection [en,de,ru]
propertyValue = Optional.fromNullable(value).or("").toString();
propertyValue = propertyValue.substring(1, propertyValue.length() - 1);
} else {
// Object.toString()
propertyValue = Optional.fromNullable(value).or("").toString();
}
String propertyName = entry.getKey().toString();
pippoSettings.overrideSetting(propertyName, propertyValue);
}
return pippoSettings;
}
|
java
|
public static PippoSettings getPippoSettings(Settings settings) {
RuntimeMode runtimeMode = RuntimeMode.PROD;
for (RuntimeMode mode : RuntimeMode.values()) {
if (mode.name().equalsIgnoreCase(settings.getMode().toString())) {
runtimeMode = mode;
}
}
final Properties properties = settings.toProperties();
final PippoSettings pippoSettings = new PippoSettings(runtimeMode);
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Object value = entry.getValue();
String propertyValue;
if (value instanceof Collection) {
// strip brackets from collection [en,de,ru]
propertyValue = Optional.fromNullable(value).or("").toString();
propertyValue = propertyValue.substring(1, propertyValue.length() - 1);
} else {
// Object.toString()
propertyValue = Optional.fromNullable(value).or("").toString();
}
String propertyName = entry.getKey().toString();
pippoSettings.overrideSetting(propertyName, propertyValue);
}
return pippoSettings;
}
|
[
"public",
"static",
"PippoSettings",
"getPippoSettings",
"(",
"Settings",
"settings",
")",
"{",
"RuntimeMode",
"runtimeMode",
"=",
"RuntimeMode",
".",
"PROD",
";",
"for",
"(",
"RuntimeMode",
"mode",
":",
"RuntimeMode",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"mode",
".",
"name",
"(",
")",
".",
"equalsIgnoreCase",
"(",
"settings",
".",
"getMode",
"(",
")",
".",
"toString",
"(",
")",
")",
")",
"{",
"runtimeMode",
"=",
"mode",
";",
"}",
"}",
"final",
"Properties",
"properties",
"=",
"settings",
".",
"toProperties",
"(",
")",
";",
"final",
"PippoSettings",
"pippoSettings",
"=",
"new",
"PippoSettings",
"(",
"runtimeMode",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Object",
",",
"Object",
">",
"entry",
":",
"properties",
".",
"entrySet",
"(",
")",
")",
"{",
"Object",
"value",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"String",
"propertyValue",
";",
"if",
"(",
"value",
"instanceof",
"Collection",
")",
"{",
"// strip brackets from collection [en,de,ru]",
"propertyValue",
"=",
"Optional",
".",
"fromNullable",
"(",
"value",
")",
".",
"or",
"(",
"\"\"",
")",
".",
"toString",
"(",
")",
";",
"propertyValue",
"=",
"propertyValue",
".",
"substring",
"(",
"1",
",",
"propertyValue",
".",
"length",
"(",
")",
"-",
"1",
")",
";",
"}",
"else",
"{",
"// Object.toString()",
"propertyValue",
"=",
"Optional",
".",
"fromNullable",
"(",
"value",
")",
".",
"or",
"(",
"\"\"",
")",
".",
"toString",
"(",
")",
";",
"}",
"String",
"propertyName",
"=",
"entry",
".",
"getKey",
"(",
")",
".",
"toString",
"(",
")",
";",
"pippoSettings",
".",
"overrideSetting",
"(",
"propertyName",
",",
"propertyValue",
")",
";",
"}",
"return",
"pippoSettings",
";",
"}"
] |
Convert Fathom Settings into PippoSettings
@param settings
@return PippoSettings
|
[
"Convert",
"Fathom",
"Settings",
"into",
"PippoSettings"
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest/src/main/java/fathom/rest/RestModule.java#L86-L113
|
10,615
|
gitblit/fathom
|
fathom-security/src/main/java/fathom/realm/FileRealm.java
|
FileRealm.readFile
|
protected synchronized void readFile() {
if (realmFile != null && realmFile.exists() && (realmFile.lastModified() != lastModified)) {
lastModified = realmFile.lastModified();
try {
Preconditions.checkArgument(realmFile.canRead(), "The file '{}' can not be read!", realmFile);
Config config = ConfigFactory.parseFile(realmFile);
super.setup(config);
} catch (Exception e) {
log.error("Failed to read {}", realmFile, e);
}
}
}
|
java
|
protected synchronized void readFile() {
if (realmFile != null && realmFile.exists() && (realmFile.lastModified() != lastModified)) {
lastModified = realmFile.lastModified();
try {
Preconditions.checkArgument(realmFile.canRead(), "The file '{}' can not be read!", realmFile);
Config config = ConfigFactory.parseFile(realmFile);
super.setup(config);
} catch (Exception e) {
log.error("Failed to read {}", realmFile, e);
}
}
}
|
[
"protected",
"synchronized",
"void",
"readFile",
"(",
")",
"{",
"if",
"(",
"realmFile",
"!=",
"null",
"&&",
"realmFile",
".",
"exists",
"(",
")",
"&&",
"(",
"realmFile",
".",
"lastModified",
"(",
")",
"!=",
"lastModified",
")",
")",
"{",
"lastModified",
"=",
"realmFile",
".",
"lastModified",
"(",
")",
";",
"try",
"{",
"Preconditions",
".",
"checkArgument",
"(",
"realmFile",
".",
"canRead",
"(",
")",
",",
"\"The file '{}' can not be read!\"",
",",
"realmFile",
")",
";",
"Config",
"config",
"=",
"ConfigFactory",
".",
"parseFile",
"(",
"realmFile",
")",
";",
"super",
".",
"setup",
"(",
"config",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to read {}\"",
",",
"realmFile",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Reads the realm file and rebuilds the in-memory lookup tables.
|
[
"Reads",
"the",
"realm",
"file",
"and",
"rebuilds",
"the",
"in",
"-",
"memory",
"lookup",
"tables",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-security/src/main/java/fathom/realm/FileRealm.java#L81-L92
|
10,616
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/ACE.java
|
ACE.newInstance
|
public static ACE newInstance(final AceType type) {
final ACE ace = new ACE();
ace.setType(type);
return ace;
}
|
java
|
public static ACE newInstance(final AceType type) {
final ACE ace = new ACE();
ace.setType(type);
return ace;
}
|
[
"public",
"static",
"ACE",
"newInstance",
"(",
"final",
"AceType",
"type",
")",
"{",
"final",
"ACE",
"ace",
"=",
"new",
"ACE",
"(",
")",
";",
"ace",
".",
"setType",
"(",
"type",
")",
";",
"return",
"ace",
";",
"}"
] |
Creates a new ACE instance.
@param type ACE type.
@return ACE.
|
[
"Creates",
"a",
"new",
"ACE",
"instance",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/ACE.java#L98-L102
|
10,617
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/ACE.java
|
ACE.parse
|
int parse(final IntBuffer buff, final int start) {
int pos = start;
byte[] bytes = NumberFacility.getBytes(buff.get(pos));
type = AceType.parseValue(bytes[0]);
flags = AceFlag.parseValue(bytes[1]);
int size = NumberFacility.getInt(bytes[3], bytes[2]);
pos++;
rights = AceRights.parseValue(NumberFacility.getReverseInt(buff.get(pos)));
if (type == AceType.ACCESS_ALLOWED_OBJECT_ACE_TYPE || type == AceType.ACCESS_DENIED_OBJECT_ACE_TYPE) {
pos++;
objectFlags = AceObjectFlags.parseValue(NumberFacility.getReverseInt(buff.get(pos)));
if (objectFlags.getFlags().contains(AceObjectFlags.Flag.ACE_OBJECT_TYPE_PRESENT)) {
objectType = new byte[16];
for (int j = 0; j < 4; j++) {
pos++;
System.arraycopy(NumberFacility.getBytes(buff.get(pos)), 0, objectType, j * 4, 4);
}
}
if (objectFlags.getFlags().contains(AceObjectFlags.Flag.ACE_INHERITED_OBJECT_TYPE_PRESENT)) {
inheritedObjectType = new byte[16];
for (int j = 0; j < 4; j++) {
pos++;
System.arraycopy(NumberFacility.getBytes(buff.get(pos)), 0, inheritedObjectType, j * 4, 4);
}
}
}
pos++;
sid = new SID();
pos = sid.parse(buff, pos);
int lastPos = start + (size / 4) - 1;
applicationData = new byte[4 * (lastPos - pos)];
int index = 0;
while (pos < lastPos) {
pos++;
System.arraycopy(NumberFacility.getBytes(buff.get(pos)), 0, applicationData, index, 4);
index += 4;
}
return pos;
}
|
java
|
int parse(final IntBuffer buff, final int start) {
int pos = start;
byte[] bytes = NumberFacility.getBytes(buff.get(pos));
type = AceType.parseValue(bytes[0]);
flags = AceFlag.parseValue(bytes[1]);
int size = NumberFacility.getInt(bytes[3], bytes[2]);
pos++;
rights = AceRights.parseValue(NumberFacility.getReverseInt(buff.get(pos)));
if (type == AceType.ACCESS_ALLOWED_OBJECT_ACE_TYPE || type == AceType.ACCESS_DENIED_OBJECT_ACE_TYPE) {
pos++;
objectFlags = AceObjectFlags.parseValue(NumberFacility.getReverseInt(buff.get(pos)));
if (objectFlags.getFlags().contains(AceObjectFlags.Flag.ACE_OBJECT_TYPE_PRESENT)) {
objectType = new byte[16];
for (int j = 0; j < 4; j++) {
pos++;
System.arraycopy(NumberFacility.getBytes(buff.get(pos)), 0, objectType, j * 4, 4);
}
}
if (objectFlags.getFlags().contains(AceObjectFlags.Flag.ACE_INHERITED_OBJECT_TYPE_PRESENT)) {
inheritedObjectType = new byte[16];
for (int j = 0; j < 4; j++) {
pos++;
System.arraycopy(NumberFacility.getBytes(buff.get(pos)), 0, inheritedObjectType, j * 4, 4);
}
}
}
pos++;
sid = new SID();
pos = sid.parse(buff, pos);
int lastPos = start + (size / 4) - 1;
applicationData = new byte[4 * (lastPos - pos)];
int index = 0;
while (pos < lastPos) {
pos++;
System.arraycopy(NumberFacility.getBytes(buff.get(pos)), 0, applicationData, index, 4);
index += 4;
}
return pos;
}
|
[
"int",
"parse",
"(",
"final",
"IntBuffer",
"buff",
",",
"final",
"int",
"start",
")",
"{",
"int",
"pos",
"=",
"start",
";",
"byte",
"[",
"]",
"bytes",
"=",
"NumberFacility",
".",
"getBytes",
"(",
"buff",
".",
"get",
"(",
"pos",
")",
")",
";",
"type",
"=",
"AceType",
".",
"parseValue",
"(",
"bytes",
"[",
"0",
"]",
")",
";",
"flags",
"=",
"AceFlag",
".",
"parseValue",
"(",
"bytes",
"[",
"1",
"]",
")",
";",
"int",
"size",
"=",
"NumberFacility",
".",
"getInt",
"(",
"bytes",
"[",
"3",
"]",
",",
"bytes",
"[",
"2",
"]",
")",
";",
"pos",
"++",
";",
"rights",
"=",
"AceRights",
".",
"parseValue",
"(",
"NumberFacility",
".",
"getReverseInt",
"(",
"buff",
".",
"get",
"(",
"pos",
")",
")",
")",
";",
"if",
"(",
"type",
"==",
"AceType",
".",
"ACCESS_ALLOWED_OBJECT_ACE_TYPE",
"||",
"type",
"==",
"AceType",
".",
"ACCESS_DENIED_OBJECT_ACE_TYPE",
")",
"{",
"pos",
"++",
";",
"objectFlags",
"=",
"AceObjectFlags",
".",
"parseValue",
"(",
"NumberFacility",
".",
"getReverseInt",
"(",
"buff",
".",
"get",
"(",
"pos",
")",
")",
")",
";",
"if",
"(",
"objectFlags",
".",
"getFlags",
"(",
")",
".",
"contains",
"(",
"AceObjectFlags",
".",
"Flag",
".",
"ACE_OBJECT_TYPE_PRESENT",
")",
")",
"{",
"objectType",
"=",
"new",
"byte",
"[",
"16",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"4",
";",
"j",
"++",
")",
"{",
"pos",
"++",
";",
"System",
".",
"arraycopy",
"(",
"NumberFacility",
".",
"getBytes",
"(",
"buff",
".",
"get",
"(",
"pos",
")",
")",
",",
"0",
",",
"objectType",
",",
"j",
"*",
"4",
",",
"4",
")",
";",
"}",
"}",
"if",
"(",
"objectFlags",
".",
"getFlags",
"(",
")",
".",
"contains",
"(",
"AceObjectFlags",
".",
"Flag",
".",
"ACE_INHERITED_OBJECT_TYPE_PRESENT",
")",
")",
"{",
"inheritedObjectType",
"=",
"new",
"byte",
"[",
"16",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"4",
";",
"j",
"++",
")",
"{",
"pos",
"++",
";",
"System",
".",
"arraycopy",
"(",
"NumberFacility",
".",
"getBytes",
"(",
"buff",
".",
"get",
"(",
"pos",
")",
")",
",",
"0",
",",
"inheritedObjectType",
",",
"j",
"*",
"4",
",",
"4",
")",
";",
"}",
"}",
"}",
"pos",
"++",
";",
"sid",
"=",
"new",
"SID",
"(",
")",
";",
"pos",
"=",
"sid",
".",
"parse",
"(",
"buff",
",",
"pos",
")",
";",
"int",
"lastPos",
"=",
"start",
"+",
"(",
"size",
"/",
"4",
")",
"-",
"1",
";",
"applicationData",
"=",
"new",
"byte",
"[",
"4",
"*",
"(",
"lastPos",
"-",
"pos",
")",
"]",
";",
"int",
"index",
"=",
"0",
";",
"while",
"(",
"pos",
"<",
"lastPos",
")",
"{",
"pos",
"++",
";",
"System",
".",
"arraycopy",
"(",
"NumberFacility",
".",
"getBytes",
"(",
"buff",
".",
"get",
"(",
"pos",
")",
")",
",",
"0",
",",
"applicationData",
",",
"index",
",",
"4",
")",
";",
"index",
"+=",
"4",
";",
"}",
"return",
"pos",
";",
"}"
] |
Load the ACE from the buffer returning the last ACE segment position into the buffer.
@param buff source buffer.
@param start start loading position.
@return last loading position.
|
[
"Load",
"the",
"ACE",
"from",
"the",
"buffer",
"returning",
"the",
"last",
"ACE",
"segment",
"position",
"into",
"the",
"buffer",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/ACE.java#L111-L159
|
10,618
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/ACE.java
|
ACE.getApplicationData
|
public byte[] getApplicationData() {
return this.applicationData == null || this.applicationData.length == 0
? null
: Arrays.copyOf(this.applicationData, this.applicationData.length);
}
|
java
|
public byte[] getApplicationData() {
return this.applicationData == null || this.applicationData.length == 0
? null
: Arrays.copyOf(this.applicationData, this.applicationData.length);
}
|
[
"public",
"byte",
"[",
"]",
"getApplicationData",
"(",
")",
"{",
"return",
"this",
".",
"applicationData",
"==",
"null",
"||",
"this",
".",
"applicationData",
".",
"length",
"==",
"0",
"?",
"null",
":",
"Arrays",
".",
"copyOf",
"(",
"this",
".",
"applicationData",
",",
"this",
".",
"applicationData",
".",
"length",
")",
";",
"}"
] |
Optional application data. The size of the application data is determined by the AceSize field.
@return application data; null if not available.
|
[
"Optional",
"application",
"data",
".",
"The",
"size",
"of",
"the",
"application",
"data",
"is",
"determined",
"by",
"the",
"AceSize",
"field",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/ACE.java#L186-L190
|
10,619
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/ACE.java
|
ACE.setApplicationData
|
public void setApplicationData(final byte[] applicationData) {
this.applicationData = applicationData == null || applicationData.length == 0
? null
: Arrays.copyOf(applicationData, applicationData.length);
}
|
java
|
public void setApplicationData(final byte[] applicationData) {
this.applicationData = applicationData == null || applicationData.length == 0
? null
: Arrays.copyOf(applicationData, applicationData.length);
}
|
[
"public",
"void",
"setApplicationData",
"(",
"final",
"byte",
"[",
"]",
"applicationData",
")",
"{",
"this",
".",
"applicationData",
"=",
"applicationData",
"==",
"null",
"||",
"applicationData",
".",
"length",
"==",
"0",
"?",
"null",
":",
"Arrays",
".",
"copyOf",
"(",
"applicationData",
",",
"applicationData",
".",
"length",
")",
";",
"}"
] |
Sets application data.
@param applicationData application data.
|
[
"Sets",
"application",
"data",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/ACE.java#L197-L201
|
10,620
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/ACE.java
|
ACE.getSize
|
public int getSize() {
return 8 + (objectFlags == null ? 0 : 4)
+ (objectType == null ? 0 : 16)
+ (inheritedObjectType == null ? 0 : 16)
+ (sid == null ? 0 : sid.getSize())
+ (applicationData == null ? 0 : applicationData.length);
}
|
java
|
public int getSize() {
return 8 + (objectFlags == null ? 0 : 4)
+ (objectType == null ? 0 : 16)
+ (inheritedObjectType == null ? 0 : 16)
+ (sid == null ? 0 : sid.getSize())
+ (applicationData == null ? 0 : applicationData.length);
}
|
[
"public",
"int",
"getSize",
"(",
")",
"{",
"return",
"8",
"+",
"(",
"objectFlags",
"==",
"null",
"?",
"0",
":",
"4",
")",
"+",
"(",
"objectType",
"==",
"null",
"?",
"0",
":",
"16",
")",
"+",
"(",
"inheritedObjectType",
"==",
"null",
"?",
"0",
":",
"16",
")",
"+",
"(",
"sid",
"==",
"null",
"?",
"0",
":",
"sid",
".",
"getSize",
"(",
")",
")",
"+",
"(",
"applicationData",
"==",
"null",
"?",
"0",
":",
"applicationData",
".",
"length",
")",
";",
"}"
] |
An unsigned 16-bit integer that specifies the size, in bytes, of the ACE. The AceSize field can be greater than
the sum of the individual fields, but MUST be a multiple of 4 to ensure alignment on a DWORD boundary. In cases
where the AceSize field encompasses additional data for the callback ACEs types, that data is
implementation-specific. Otherwise, this additional data is not interpreted and MUST be ignored.
@return ACE size.
|
[
"An",
"unsigned",
"16",
"-",
"bit",
"integer",
"that",
"specifies",
"the",
"size",
"in",
"bytes",
"of",
"the",
"ACE",
".",
"The",
"AceSize",
"field",
"can",
"be",
"greater",
"than",
"the",
"sum",
"of",
"the",
"individual",
"fields",
"but",
"MUST",
"be",
"a",
"multiple",
"of",
"4",
"to",
"ensure",
"alignment",
"on",
"a",
"DWORD",
"boundary",
".",
"In",
"cases",
"where",
"the",
"AceSize",
"field",
"encompasses",
"additional",
"data",
"for",
"the",
"callback",
"ACEs",
"types",
"that",
"data",
"is",
"implementation",
"-",
"specific",
".",
"Otherwise",
"this",
"additional",
"data",
"is",
"not",
"interpreted",
"and",
"MUST",
"be",
"ignored",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/ACE.java#L276-L282
|
10,621
|
gitblit/fathom
|
fathom-core/src/main/java/fathom/Module.java
|
Module.install
|
protected void install(Module module) {
module.setSettings(settings);
module.setServices(services);
binder().install(module);
}
|
java
|
protected void install(Module module) {
module.setSettings(settings);
module.setServices(services);
binder().install(module);
}
|
[
"protected",
"void",
"install",
"(",
"Module",
"module",
")",
"{",
"module",
".",
"setSettings",
"(",
"settings",
")",
";",
"module",
".",
"setServices",
"(",
"services",
")",
";",
"binder",
"(",
")",
".",
"install",
"(",
"module",
")",
";",
"}"
] |
Install a Fathom Module.
|
[
"Install",
"a",
"Fathom",
"Module",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-core/src/main/java/fathom/Module.java#L79-L83
|
10,622
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/data/AceObjectFlags.java
|
AceObjectFlags.parseValue
|
public static AceObjectFlags parseValue(final int value) {
final AceObjectFlags res = new AceObjectFlags();
res.others = value;
for (AceObjectFlags.Flag type : AceObjectFlags.Flag.values()) {
if ((value & type.getValue()) == type.getValue()) {
res.flags.add(type);
res.others ^= type.getValue();
}
}
return res;
}
|
java
|
public static AceObjectFlags parseValue(final int value) {
final AceObjectFlags res = new AceObjectFlags();
res.others = value;
for (AceObjectFlags.Flag type : AceObjectFlags.Flag.values()) {
if ((value & type.getValue()) == type.getValue()) {
res.flags.add(type);
res.others ^= type.getValue();
}
}
return res;
}
|
[
"public",
"static",
"AceObjectFlags",
"parseValue",
"(",
"final",
"int",
"value",
")",
"{",
"final",
"AceObjectFlags",
"res",
"=",
"new",
"AceObjectFlags",
"(",
")",
";",
"res",
".",
"others",
"=",
"value",
";",
"for",
"(",
"AceObjectFlags",
".",
"Flag",
"type",
":",
"AceObjectFlags",
".",
"Flag",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"(",
"value",
"&",
"type",
".",
"getValue",
"(",
")",
")",
"==",
"type",
".",
"getValue",
"(",
")",
")",
"{",
"res",
".",
"flags",
".",
"add",
"(",
"type",
")",
";",
"res",
".",
"others",
"^=",
"type",
".",
"getValue",
"(",
")",
";",
"}",
"}",
"return",
"res",
";",
"}"
] |
Parse flags given as int value.
@param value flags given as int value.
@return ACE object flags.
|
[
"Parse",
"flags",
"given",
"as",
"int",
"value",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/data/AceObjectFlags.java#L97-L110
|
10,623
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/data/AceObjectFlags.java
|
AceObjectFlags.addFlag
|
public AceObjectFlags addFlag(final Flag flag) {
if (!flags.contains(flag)) {
flags.add(flag);
}
return this;
}
|
java
|
public AceObjectFlags addFlag(final Flag flag) {
if (!flags.contains(flag)) {
flags.add(flag);
}
return this;
}
|
[
"public",
"AceObjectFlags",
"addFlag",
"(",
"final",
"Flag",
"flag",
")",
"{",
"if",
"(",
"!",
"flags",
".",
"contains",
"(",
"flag",
")",
")",
"{",
"flags",
".",
"add",
"(",
"flag",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Adds standard ACE object flag.
@param flag standard ACE object flag.
@return the current ACE object flags.
|
[
"Adds",
"standard",
"ACE",
"object",
"flag",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/data/AceObjectFlags.java#L127-L132
|
10,624
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.openKeyStore
|
public static KeyStore openKeyStore(File storeFile, String storePassword) {
String lc = storeFile.getName().toLowerCase();
String type = "JKS";
String provider = null;
if (lc.endsWith(".p12") || lc.endsWith(".pfx")) {
type = "PKCS12";
provider = BC;
}
try {
KeyStore store;
if (provider == null) {
store = KeyStore.getInstance(type);
} else {
store = KeyStore.getInstance(type, provider);
}
storeFile.getParentFile().mkdirs();
if (storeFile.exists()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(storeFile);
store.load(fis, storePassword.toCharArray());
} finally {
if (fis != null) {
fis.close();
}
}
} else {
store.load(null);
}
return store;
} catch (Exception e) {
throw new RuntimeException("Could not open keystore " + storeFile, e);
}
}
|
java
|
public static KeyStore openKeyStore(File storeFile, String storePassword) {
String lc = storeFile.getName().toLowerCase();
String type = "JKS";
String provider = null;
if (lc.endsWith(".p12") || lc.endsWith(".pfx")) {
type = "PKCS12";
provider = BC;
}
try {
KeyStore store;
if (provider == null) {
store = KeyStore.getInstance(type);
} else {
store = KeyStore.getInstance(type, provider);
}
storeFile.getParentFile().mkdirs();
if (storeFile.exists()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(storeFile);
store.load(fis, storePassword.toCharArray());
} finally {
if (fis != null) {
fis.close();
}
}
} else {
store.load(null);
}
return store;
} catch (Exception e) {
throw new RuntimeException("Could not open keystore " + storeFile, e);
}
}
|
[
"public",
"static",
"KeyStore",
"openKeyStore",
"(",
"File",
"storeFile",
",",
"String",
"storePassword",
")",
"{",
"String",
"lc",
"=",
"storeFile",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"String",
"type",
"=",
"\"JKS\"",
";",
"String",
"provider",
"=",
"null",
";",
"if",
"(",
"lc",
".",
"endsWith",
"(",
"\".p12\"",
")",
"||",
"lc",
".",
"endsWith",
"(",
"\".pfx\"",
")",
")",
"{",
"type",
"=",
"\"PKCS12\"",
";",
"provider",
"=",
"BC",
";",
"}",
"try",
"{",
"KeyStore",
"store",
";",
"if",
"(",
"provider",
"==",
"null",
")",
"{",
"store",
"=",
"KeyStore",
".",
"getInstance",
"(",
"type",
")",
";",
"}",
"else",
"{",
"store",
"=",
"KeyStore",
".",
"getInstance",
"(",
"type",
",",
"provider",
")",
";",
"}",
"storeFile",
".",
"getParentFile",
"(",
")",
".",
"mkdirs",
"(",
")",
";",
"if",
"(",
"storeFile",
".",
"exists",
"(",
")",
")",
"{",
"FileInputStream",
"fis",
"=",
"null",
";",
"try",
"{",
"fis",
"=",
"new",
"FileInputStream",
"(",
"storeFile",
")",
";",
"store",
".",
"load",
"(",
"fis",
",",
"storePassword",
".",
"toCharArray",
"(",
")",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"fis",
"!=",
"null",
")",
"{",
"fis",
".",
"close",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"store",
".",
"load",
"(",
"null",
")",
";",
"}",
"return",
"store",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not open keystore \"",
"+",
"storeFile",
",",
"e",
")",
";",
"}",
"}"
] |
Open a keystore. Store type is determined by file extension of name. If
undetermined, JKS is assumed. The keystore does not need to exist.
@param storeFile
@param storePassword
@return a KeyStore
|
[
"Open",
"a",
"keystore",
".",
"Store",
"type",
"is",
"determined",
"by",
"file",
"extension",
"of",
"name",
".",
"If",
"undetermined",
"JKS",
"is",
"assumed",
".",
"The",
"keystore",
"does",
"not",
"need",
"to",
"exist",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L305-L339
|
10,625
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.saveKeyStore
|
public static void saveKeyStore(File targetStoreFile, KeyStore store, String password) {
File folder = targetStoreFile.getAbsoluteFile().getParentFile();
if (!folder.exists()) {
folder.mkdirs();
}
File tmpFile = new File(folder, Long.toHexString(System.currentTimeMillis()) + ".tmp");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tmpFile);
store.store(fos, password.toCharArray());
fos.flush();
fos.close();
if (targetStoreFile.exists()) {
targetStoreFile.delete();
}
tmpFile.renameTo(targetStoreFile);
} catch (IOException e) {
String message = e.getMessage().toLowerCase();
if (message.contains("illegal key size")) {
throw new RuntimeException("Illegal Key Size! You might consider installing the JCE Unlimited Strength Jurisdiction Policy files for your JVM.");
} else {
throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
}
} catch (Exception e) {
throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
if (tmpFile.exists()) {
tmpFile.delete();
}
}
}
|
java
|
public static void saveKeyStore(File targetStoreFile, KeyStore store, String password) {
File folder = targetStoreFile.getAbsoluteFile().getParentFile();
if (!folder.exists()) {
folder.mkdirs();
}
File tmpFile = new File(folder, Long.toHexString(System.currentTimeMillis()) + ".tmp");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tmpFile);
store.store(fos, password.toCharArray());
fos.flush();
fos.close();
if (targetStoreFile.exists()) {
targetStoreFile.delete();
}
tmpFile.renameTo(targetStoreFile);
} catch (IOException e) {
String message = e.getMessage().toLowerCase();
if (message.contains("illegal key size")) {
throw new RuntimeException("Illegal Key Size! You might consider installing the JCE Unlimited Strength Jurisdiction Policy files for your JVM.");
} else {
throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
}
} catch (Exception e) {
throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
if (tmpFile.exists()) {
tmpFile.delete();
}
}
}
|
[
"public",
"static",
"void",
"saveKeyStore",
"(",
"File",
"targetStoreFile",
",",
"KeyStore",
"store",
",",
"String",
"password",
")",
"{",
"File",
"folder",
"=",
"targetStoreFile",
".",
"getAbsoluteFile",
"(",
")",
".",
"getParentFile",
"(",
")",
";",
"if",
"(",
"!",
"folder",
".",
"exists",
"(",
")",
")",
"{",
"folder",
".",
"mkdirs",
"(",
")",
";",
"}",
"File",
"tmpFile",
"=",
"new",
"File",
"(",
"folder",
",",
"Long",
".",
"toHexString",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
"+",
"\".tmp\"",
")",
";",
"FileOutputStream",
"fos",
"=",
"null",
";",
"try",
"{",
"fos",
"=",
"new",
"FileOutputStream",
"(",
"tmpFile",
")",
";",
"store",
".",
"store",
"(",
"fos",
",",
"password",
".",
"toCharArray",
"(",
")",
")",
";",
"fos",
".",
"flush",
"(",
")",
";",
"fos",
".",
"close",
"(",
")",
";",
"if",
"(",
"targetStoreFile",
".",
"exists",
"(",
")",
")",
"{",
"targetStoreFile",
".",
"delete",
"(",
")",
";",
"}",
"tmpFile",
".",
"renameTo",
"(",
"targetStoreFile",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"String",
"message",
"=",
"e",
".",
"getMessage",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"message",
".",
"contains",
"(",
"\"illegal key size\"",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Illegal Key Size! You might consider installing the JCE Unlimited Strength Jurisdiction Policy files for your JVM.\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not save keystore \"",
"+",
"targetStoreFile",
",",
"e",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not save keystore \"",
"+",
"targetStoreFile",
",",
"e",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"fos",
"!=",
"null",
")",
"{",
"try",
"{",
"fos",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"tmpFile",
".",
"exists",
"(",
")",
")",
"{",
"tmpFile",
".",
"delete",
"(",
")",
";",
"}",
"}",
"}"
] |
Saves the keystore to the specified file.
@param targetStoreFile
@param store
@param password
|
[
"Saves",
"the",
"keystore",
"to",
"the",
"specified",
"file",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L348-L385
|
10,626
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.getCertificate
|
public static X509Certificate getCertificate(String alias, File storeFile, String storePassword) {
try {
KeyStore store = openKeyStore(storeFile, storePassword);
X509Certificate caCert = (X509Certificate) store.getCertificate(alias);
return caCert;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
public static X509Certificate getCertificate(String alias, File storeFile, String storePassword) {
try {
KeyStore store = openKeyStore(storeFile, storePassword);
X509Certificate caCert = (X509Certificate) store.getCertificate(alias);
return caCert;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"static",
"X509Certificate",
"getCertificate",
"(",
"String",
"alias",
",",
"File",
"storeFile",
",",
"String",
"storePassword",
")",
"{",
"try",
"{",
"KeyStore",
"store",
"=",
"openKeyStore",
"(",
"storeFile",
",",
"storePassword",
")",
";",
"X509Certificate",
"caCert",
"=",
"(",
"X509Certificate",
")",
"store",
".",
"getCertificate",
"(",
"alias",
")",
";",
"return",
"caCert",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Retrieves the X509 certificate with the specified alias from the certificate
store.
@param alias
@param storeFile
@param storePassword
@return the certificate
|
[
"Retrieves",
"the",
"X509",
"certificate",
"with",
"the",
"specified",
"alias",
"from",
"the",
"certificate",
"store",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L396-L404
|
10,627
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.getPrivateKey
|
public static PrivateKey getPrivateKey(String alias, File storeFile, String storePassword) {
try {
KeyStore store = openKeyStore(storeFile, storePassword);
PrivateKey key = (PrivateKey) store.getKey(alias, storePassword.toCharArray());
return key;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
public static PrivateKey getPrivateKey(String alias, File storeFile, String storePassword) {
try {
KeyStore store = openKeyStore(storeFile, storePassword);
PrivateKey key = (PrivateKey) store.getKey(alias, storePassword.toCharArray());
return key;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"static",
"PrivateKey",
"getPrivateKey",
"(",
"String",
"alias",
",",
"File",
"storeFile",
",",
"String",
"storePassword",
")",
"{",
"try",
"{",
"KeyStore",
"store",
"=",
"openKeyStore",
"(",
"storeFile",
",",
"storePassword",
")",
";",
"PrivateKey",
"key",
"=",
"(",
"PrivateKey",
")",
"store",
".",
"getKey",
"(",
"alias",
",",
"storePassword",
".",
"toCharArray",
"(",
")",
")",
";",
"return",
"key",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Retrieves the private key for the specified alias from the certificate
store.
@param alias
@param storeFile
@param storePassword
@return the private key
|
[
"Retrieves",
"the",
"private",
"key",
"for",
"the",
"specified",
"alias",
"from",
"the",
"certificate",
"store",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L415-L423
|
10,628
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.saveCertificate
|
public static void saveCertificate(X509Certificate cert, File targetFile) {
File folder = targetFile.getAbsoluteFile().getParentFile();
if (!folder.exists()) {
folder.mkdirs();
}
File tmpFile = new File(folder, Long.toHexString(System.currentTimeMillis()) + ".tmp");
try {
boolean asPem = targetFile.getName().toLowerCase().endsWith(".pem");
if (asPem) {
// PEM encoded X509
PEMWriter pemWriter = null;
try {
pemWriter = new PEMWriter(new FileWriter(tmpFile));
pemWriter.writeObject(cert);
pemWriter.flush();
} finally {
if (pemWriter != null) {
pemWriter.close();
}
}
} else {
// DER encoded X509
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tmpFile);
fos.write(cert.getEncoded());
fos.flush();
} finally {
if (fos != null) {
fos.close();
}
}
}
// rename tmp file to target
if (targetFile.exists()) {
targetFile.delete();
}
tmpFile.renameTo(targetFile);
} catch (Exception e) {
if (tmpFile.exists()) {
tmpFile.delete();
}
throw new RuntimeException("Failed to save certificate " + cert.getSubjectX500Principal().getName(), e);
}
}
|
java
|
public static void saveCertificate(X509Certificate cert, File targetFile) {
File folder = targetFile.getAbsoluteFile().getParentFile();
if (!folder.exists()) {
folder.mkdirs();
}
File tmpFile = new File(folder, Long.toHexString(System.currentTimeMillis()) + ".tmp");
try {
boolean asPem = targetFile.getName().toLowerCase().endsWith(".pem");
if (asPem) {
// PEM encoded X509
PEMWriter pemWriter = null;
try {
pemWriter = new PEMWriter(new FileWriter(tmpFile));
pemWriter.writeObject(cert);
pemWriter.flush();
} finally {
if (pemWriter != null) {
pemWriter.close();
}
}
} else {
// DER encoded X509
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tmpFile);
fos.write(cert.getEncoded());
fos.flush();
} finally {
if (fos != null) {
fos.close();
}
}
}
// rename tmp file to target
if (targetFile.exists()) {
targetFile.delete();
}
tmpFile.renameTo(targetFile);
} catch (Exception e) {
if (tmpFile.exists()) {
tmpFile.delete();
}
throw new RuntimeException("Failed to save certificate " + cert.getSubjectX500Principal().getName(), e);
}
}
|
[
"public",
"static",
"void",
"saveCertificate",
"(",
"X509Certificate",
"cert",
",",
"File",
"targetFile",
")",
"{",
"File",
"folder",
"=",
"targetFile",
".",
"getAbsoluteFile",
"(",
")",
".",
"getParentFile",
"(",
")",
";",
"if",
"(",
"!",
"folder",
".",
"exists",
"(",
")",
")",
"{",
"folder",
".",
"mkdirs",
"(",
")",
";",
"}",
"File",
"tmpFile",
"=",
"new",
"File",
"(",
"folder",
",",
"Long",
".",
"toHexString",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
"+",
"\".tmp\"",
")",
";",
"try",
"{",
"boolean",
"asPem",
"=",
"targetFile",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"endsWith",
"(",
"\".pem\"",
")",
";",
"if",
"(",
"asPem",
")",
"{",
"// PEM encoded X509",
"PEMWriter",
"pemWriter",
"=",
"null",
";",
"try",
"{",
"pemWriter",
"=",
"new",
"PEMWriter",
"(",
"new",
"FileWriter",
"(",
"tmpFile",
")",
")",
";",
"pemWriter",
".",
"writeObject",
"(",
"cert",
")",
";",
"pemWriter",
".",
"flush",
"(",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"pemWriter",
"!=",
"null",
")",
"{",
"pemWriter",
".",
"close",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// DER encoded X509",
"FileOutputStream",
"fos",
"=",
"null",
";",
"try",
"{",
"fos",
"=",
"new",
"FileOutputStream",
"(",
"tmpFile",
")",
";",
"fos",
".",
"write",
"(",
"cert",
".",
"getEncoded",
"(",
")",
")",
";",
"fos",
".",
"flush",
"(",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"fos",
"!=",
"null",
")",
"{",
"fos",
".",
"close",
"(",
")",
";",
"}",
"}",
"}",
"// rename tmp file to target",
"if",
"(",
"targetFile",
".",
"exists",
"(",
")",
")",
"{",
"targetFile",
".",
"delete",
"(",
")",
";",
"}",
"tmpFile",
".",
"renameTo",
"(",
"targetFile",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"if",
"(",
"tmpFile",
".",
"exists",
"(",
")",
")",
"{",
"tmpFile",
".",
"delete",
"(",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"Failed to save certificate \"",
"+",
"cert",
".",
"getSubjectX500Principal",
"(",
")",
".",
"getName",
"(",
")",
",",
"e",
")",
";",
"}",
"}"
] |
Saves the certificate to the file system. If the destination filename
ends with the pem extension, the certificate is written in the PEM format,
otherwise the certificate is written in the DER format.
@param cert
@param targetFile
|
[
"Saves",
"the",
"certificate",
"to",
"the",
"file",
"system",
".",
"If",
"the",
"destination",
"filename",
"ends",
"with",
"the",
"pem",
"extension",
"the",
"certificate",
"is",
"written",
"in",
"the",
"PEM",
"format",
"otherwise",
"the",
"certificate",
"is",
"written",
"in",
"the",
"DER",
"format",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L433-L478
|
10,629
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.newKeyPair
|
private static KeyPair newKeyPair() throws Exception {
KeyPairGenerator kpGen = KeyPairGenerator.getInstance(KEY_ALGORITHM, BC);
kpGen.initialize(KEY_LENGTH, new SecureRandom());
return kpGen.generateKeyPair();
}
|
java
|
private static KeyPair newKeyPair() throws Exception {
KeyPairGenerator kpGen = KeyPairGenerator.getInstance(KEY_ALGORITHM, BC);
kpGen.initialize(KEY_LENGTH, new SecureRandom());
return kpGen.generateKeyPair();
}
|
[
"private",
"static",
"KeyPair",
"newKeyPair",
"(",
")",
"throws",
"Exception",
"{",
"KeyPairGenerator",
"kpGen",
"=",
"KeyPairGenerator",
".",
"getInstance",
"(",
"KEY_ALGORITHM",
",",
"BC",
")",
";",
"kpGen",
".",
"initialize",
"(",
"KEY_LENGTH",
",",
"new",
"SecureRandom",
"(",
")",
")",
";",
"return",
"kpGen",
".",
"generateKeyPair",
"(",
")",
";",
"}"
] |
Generate a new keypair.
@return a keypair
@throws Exception
|
[
"Generate",
"a",
"new",
"keypair",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L486-L490
|
10,630
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.buildDistinguishedName
|
private static X500Name buildDistinguishedName(X509Metadata metadata) {
X500NameBuilder dnBuilder = new X500NameBuilder(BCStyle.INSTANCE);
setOID(dnBuilder, metadata, "C", null);
setOID(dnBuilder, metadata, "ST", null);
setOID(dnBuilder, metadata, "L", null);
setOID(dnBuilder, metadata, "O", "Fathom");
setOID(dnBuilder, metadata, "OU", "Fathom");
setOID(dnBuilder, metadata, "E", metadata.emailAddress);
setOID(dnBuilder, metadata, "CN", metadata.commonName);
X500Name dn = dnBuilder.build();
return dn;
}
|
java
|
private static X500Name buildDistinguishedName(X509Metadata metadata) {
X500NameBuilder dnBuilder = new X500NameBuilder(BCStyle.INSTANCE);
setOID(dnBuilder, metadata, "C", null);
setOID(dnBuilder, metadata, "ST", null);
setOID(dnBuilder, metadata, "L", null);
setOID(dnBuilder, metadata, "O", "Fathom");
setOID(dnBuilder, metadata, "OU", "Fathom");
setOID(dnBuilder, metadata, "E", metadata.emailAddress);
setOID(dnBuilder, metadata, "CN", metadata.commonName);
X500Name dn = dnBuilder.build();
return dn;
}
|
[
"private",
"static",
"X500Name",
"buildDistinguishedName",
"(",
"X509Metadata",
"metadata",
")",
"{",
"X500NameBuilder",
"dnBuilder",
"=",
"new",
"X500NameBuilder",
"(",
"BCStyle",
".",
"INSTANCE",
")",
";",
"setOID",
"(",
"dnBuilder",
",",
"metadata",
",",
"\"C\"",
",",
"null",
")",
";",
"setOID",
"(",
"dnBuilder",
",",
"metadata",
",",
"\"ST\"",
",",
"null",
")",
";",
"setOID",
"(",
"dnBuilder",
",",
"metadata",
",",
"\"L\"",
",",
"null",
")",
";",
"setOID",
"(",
"dnBuilder",
",",
"metadata",
",",
"\"O\"",
",",
"\"Fathom\"",
")",
";",
"setOID",
"(",
"dnBuilder",
",",
"metadata",
",",
"\"OU\"",
",",
"\"Fathom\"",
")",
";",
"setOID",
"(",
"dnBuilder",
",",
"metadata",
",",
"\"E\"",
",",
"metadata",
".",
"emailAddress",
")",
";",
"setOID",
"(",
"dnBuilder",
",",
"metadata",
",",
"\"CN\"",
",",
"metadata",
".",
"commonName",
")",
";",
"X500Name",
"dn",
"=",
"dnBuilder",
".",
"build",
"(",
")",
";",
"return",
"dn",
";",
"}"
] |
Builds a distinguished name from the X509Metadata.
@return a DN
|
[
"Builds",
"a",
"distinguished",
"name",
"from",
"the",
"X509Metadata",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L497-L508
|
10,631
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.newSSLCertificate
|
public static X509Certificate newSSLCertificate(X509Metadata sslMetadata, PrivateKey caPrivateKey, X509Certificate caCert, File targetStoreFile, X509Log x509log) {
try {
KeyPair pair = newKeyPair();
X500Name webDN = buildDistinguishedName(sslMetadata);
X500Name issuerDN = new X500Name(PrincipalUtil.getIssuerX509Principal(caCert).getName());
X509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(
issuerDN,
BigInteger.valueOf(System.currentTimeMillis()),
sslMetadata.notBefore,
sslMetadata.notAfter,
webDN,
pair.getPublic());
JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils();
certBuilder.addExtension(X509Extension.subjectKeyIdentifier, false, extUtils.createSubjectKeyIdentifier(pair.getPublic()));
certBuilder.addExtension(X509Extension.basicConstraints, false, new BasicConstraints(false));
certBuilder.addExtension(X509Extension.authorityKeyIdentifier, false, extUtils.createAuthorityKeyIdentifier(caCert.getPublicKey()));
// support alternateSubjectNames for SSL certificates
List<GeneralName> altNames = new ArrayList<GeneralName>();
if (isIpAddress(sslMetadata.commonName)) {
altNames.add(new GeneralName(GeneralName.iPAddress, sslMetadata.commonName));
}
if (altNames.size() > 0) {
GeneralNames subjectAltName = new GeneralNames(altNames.toArray(new GeneralName[altNames.size()]));
certBuilder.addExtension(X509Extension.subjectAlternativeName, false, subjectAltName);
}
ContentSigner caSigner = new JcaContentSignerBuilder(SIGNING_ALGORITHM)
.setProvider(BC).build(caPrivateKey);
X509Certificate cert = new JcaX509CertificateConverter().setProvider(BC)
.getCertificate(certBuilder.build(caSigner));
cert.checkValidity(new Date());
cert.verify(caCert.getPublicKey());
// Save to keystore
KeyStore serverStore = openKeyStore(targetStoreFile, sslMetadata.password);
serverStore.setKeyEntry(sslMetadata.commonName, pair.getPrivate(), sslMetadata.password.toCharArray(),
new Certificate[]{cert, caCert});
saveKeyStore(targetStoreFile, serverStore, sslMetadata.password);
x509log.log(MessageFormat.format("New SSL certificate {0,number,0} [{1}]", cert.getSerialNumber(), cert.getSubjectDN().getName()));
// update serial number in metadata object
sslMetadata.serialNumber = cert.getSerialNumber().toString();
return cert;
} catch (Throwable t) {
throw new RuntimeException("Failed to generate SSL certificate!", t);
}
}
|
java
|
public static X509Certificate newSSLCertificate(X509Metadata sslMetadata, PrivateKey caPrivateKey, X509Certificate caCert, File targetStoreFile, X509Log x509log) {
try {
KeyPair pair = newKeyPair();
X500Name webDN = buildDistinguishedName(sslMetadata);
X500Name issuerDN = new X500Name(PrincipalUtil.getIssuerX509Principal(caCert).getName());
X509v3CertificateBuilder certBuilder = new JcaX509v3CertificateBuilder(
issuerDN,
BigInteger.valueOf(System.currentTimeMillis()),
sslMetadata.notBefore,
sslMetadata.notAfter,
webDN,
pair.getPublic());
JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils();
certBuilder.addExtension(X509Extension.subjectKeyIdentifier, false, extUtils.createSubjectKeyIdentifier(pair.getPublic()));
certBuilder.addExtension(X509Extension.basicConstraints, false, new BasicConstraints(false));
certBuilder.addExtension(X509Extension.authorityKeyIdentifier, false, extUtils.createAuthorityKeyIdentifier(caCert.getPublicKey()));
// support alternateSubjectNames for SSL certificates
List<GeneralName> altNames = new ArrayList<GeneralName>();
if (isIpAddress(sslMetadata.commonName)) {
altNames.add(new GeneralName(GeneralName.iPAddress, sslMetadata.commonName));
}
if (altNames.size() > 0) {
GeneralNames subjectAltName = new GeneralNames(altNames.toArray(new GeneralName[altNames.size()]));
certBuilder.addExtension(X509Extension.subjectAlternativeName, false, subjectAltName);
}
ContentSigner caSigner = new JcaContentSignerBuilder(SIGNING_ALGORITHM)
.setProvider(BC).build(caPrivateKey);
X509Certificate cert = new JcaX509CertificateConverter().setProvider(BC)
.getCertificate(certBuilder.build(caSigner));
cert.checkValidity(new Date());
cert.verify(caCert.getPublicKey());
// Save to keystore
KeyStore serverStore = openKeyStore(targetStoreFile, sslMetadata.password);
serverStore.setKeyEntry(sslMetadata.commonName, pair.getPrivate(), sslMetadata.password.toCharArray(),
new Certificate[]{cert, caCert});
saveKeyStore(targetStoreFile, serverStore, sslMetadata.password);
x509log.log(MessageFormat.format("New SSL certificate {0,number,0} [{1}]", cert.getSerialNumber(), cert.getSubjectDN().getName()));
// update serial number in metadata object
sslMetadata.serialNumber = cert.getSerialNumber().toString();
return cert;
} catch (Throwable t) {
throw new RuntimeException("Failed to generate SSL certificate!", t);
}
}
|
[
"public",
"static",
"X509Certificate",
"newSSLCertificate",
"(",
"X509Metadata",
"sslMetadata",
",",
"PrivateKey",
"caPrivateKey",
",",
"X509Certificate",
"caCert",
",",
"File",
"targetStoreFile",
",",
"X509Log",
"x509log",
")",
"{",
"try",
"{",
"KeyPair",
"pair",
"=",
"newKeyPair",
"(",
")",
";",
"X500Name",
"webDN",
"=",
"buildDistinguishedName",
"(",
"sslMetadata",
")",
";",
"X500Name",
"issuerDN",
"=",
"new",
"X500Name",
"(",
"PrincipalUtil",
".",
"getIssuerX509Principal",
"(",
"caCert",
")",
".",
"getName",
"(",
")",
")",
";",
"X509v3CertificateBuilder",
"certBuilder",
"=",
"new",
"JcaX509v3CertificateBuilder",
"(",
"issuerDN",
",",
"BigInteger",
".",
"valueOf",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
",",
"sslMetadata",
".",
"notBefore",
",",
"sslMetadata",
".",
"notAfter",
",",
"webDN",
",",
"pair",
".",
"getPublic",
"(",
")",
")",
";",
"JcaX509ExtensionUtils",
"extUtils",
"=",
"new",
"JcaX509ExtensionUtils",
"(",
")",
";",
"certBuilder",
".",
"addExtension",
"(",
"X509Extension",
".",
"subjectKeyIdentifier",
",",
"false",
",",
"extUtils",
".",
"createSubjectKeyIdentifier",
"(",
"pair",
".",
"getPublic",
"(",
")",
")",
")",
";",
"certBuilder",
".",
"addExtension",
"(",
"X509Extension",
".",
"basicConstraints",
",",
"false",
",",
"new",
"BasicConstraints",
"(",
"false",
")",
")",
";",
"certBuilder",
".",
"addExtension",
"(",
"X509Extension",
".",
"authorityKeyIdentifier",
",",
"false",
",",
"extUtils",
".",
"createAuthorityKeyIdentifier",
"(",
"caCert",
".",
"getPublicKey",
"(",
")",
")",
")",
";",
"// support alternateSubjectNames for SSL certificates",
"List",
"<",
"GeneralName",
">",
"altNames",
"=",
"new",
"ArrayList",
"<",
"GeneralName",
">",
"(",
")",
";",
"if",
"(",
"isIpAddress",
"(",
"sslMetadata",
".",
"commonName",
")",
")",
"{",
"altNames",
".",
"add",
"(",
"new",
"GeneralName",
"(",
"GeneralName",
".",
"iPAddress",
",",
"sslMetadata",
".",
"commonName",
")",
")",
";",
"}",
"if",
"(",
"altNames",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"GeneralNames",
"subjectAltName",
"=",
"new",
"GeneralNames",
"(",
"altNames",
".",
"toArray",
"(",
"new",
"GeneralName",
"[",
"altNames",
".",
"size",
"(",
")",
"]",
")",
")",
";",
"certBuilder",
".",
"addExtension",
"(",
"X509Extension",
".",
"subjectAlternativeName",
",",
"false",
",",
"subjectAltName",
")",
";",
"}",
"ContentSigner",
"caSigner",
"=",
"new",
"JcaContentSignerBuilder",
"(",
"SIGNING_ALGORITHM",
")",
".",
"setProvider",
"(",
"BC",
")",
".",
"build",
"(",
"caPrivateKey",
")",
";",
"X509Certificate",
"cert",
"=",
"new",
"JcaX509CertificateConverter",
"(",
")",
".",
"setProvider",
"(",
"BC",
")",
".",
"getCertificate",
"(",
"certBuilder",
".",
"build",
"(",
"caSigner",
")",
")",
";",
"cert",
".",
"checkValidity",
"(",
"new",
"Date",
"(",
")",
")",
";",
"cert",
".",
"verify",
"(",
"caCert",
".",
"getPublicKey",
"(",
")",
")",
";",
"// Save to keystore",
"KeyStore",
"serverStore",
"=",
"openKeyStore",
"(",
"targetStoreFile",
",",
"sslMetadata",
".",
"password",
")",
";",
"serverStore",
".",
"setKeyEntry",
"(",
"sslMetadata",
".",
"commonName",
",",
"pair",
".",
"getPrivate",
"(",
")",
",",
"sslMetadata",
".",
"password",
".",
"toCharArray",
"(",
")",
",",
"new",
"Certificate",
"[",
"]",
"{",
"cert",
",",
"caCert",
"}",
")",
";",
"saveKeyStore",
"(",
"targetStoreFile",
",",
"serverStore",
",",
"sslMetadata",
".",
"password",
")",
";",
"x509log",
".",
"log",
"(",
"MessageFormat",
".",
"format",
"(",
"\"New SSL certificate {0,number,0} [{1}]\"",
",",
"cert",
".",
"getSerialNumber",
"(",
")",
",",
"cert",
".",
"getSubjectDN",
"(",
")",
".",
"getName",
"(",
")",
")",
")",
";",
"// update serial number in metadata object",
"sslMetadata",
".",
"serialNumber",
"=",
"cert",
".",
"getSerialNumber",
"(",
")",
".",
"toString",
"(",
")",
";",
"return",
"cert",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Failed to generate SSL certificate!\"",
",",
"t",
")",
";",
"}",
"}"
] |
Creates a new SSL certificate signed by the CA private key and stored in
keyStore.
@param sslMetadata
@param caPrivateKey
@param caCert
@param targetStoreFile
@param x509log
|
[
"Creates",
"a",
"new",
"SSL",
"certificate",
"signed",
"by",
"the",
"CA",
"private",
"key",
"and",
"stored",
"in",
"keyStore",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L542-L595
|
10,632
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.addTrustedCertificate
|
public static void addTrustedCertificate(String alias, X509Certificate cert, File storeFile, String storePassword) {
try {
KeyStore store = openKeyStore(storeFile, storePassword);
store.setCertificateEntry(alias, cert);
saveKeyStore(storeFile, store, storePassword);
} catch (Exception e) {
throw new RuntimeException("Failed to import certificate into trust store " + storeFile, e);
}
}
|
java
|
public static void addTrustedCertificate(String alias, X509Certificate cert, File storeFile, String storePassword) {
try {
KeyStore store = openKeyStore(storeFile, storePassword);
store.setCertificateEntry(alias, cert);
saveKeyStore(storeFile, store, storePassword);
} catch (Exception e) {
throw new RuntimeException("Failed to import certificate into trust store " + storeFile, e);
}
}
|
[
"public",
"static",
"void",
"addTrustedCertificate",
"(",
"String",
"alias",
",",
"X509Certificate",
"cert",
",",
"File",
"storeFile",
",",
"String",
"storePassword",
")",
"{",
"try",
"{",
"KeyStore",
"store",
"=",
"openKeyStore",
"(",
"storeFile",
",",
"storePassword",
")",
";",
"store",
".",
"setCertificateEntry",
"(",
"alias",
",",
"cert",
")",
";",
"saveKeyStore",
"(",
"storeFile",
",",
"store",
",",
"storePassword",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Failed to import certificate into trust store \"",
"+",
"storeFile",
",",
"e",
")",
";",
"}",
"}"
] |
Imports a certificate into the trust store.
@param alias
@param cert
@param storeFile
@param storePassword
|
[
"Imports",
"a",
"certificate",
"into",
"the",
"trust",
"store",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L715-L723
|
10,633
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.verifyChain
|
public static PKIXCertPathBuilderResult verifyChain(X509Certificate testCert, X509Certificate... additionalCerts) {
try {
// Check for self-signed certificate
if (isSelfSigned(testCert)) {
throw new RuntimeException("The certificate is self-signed. Nothing to verify.");
}
// Prepare a set of all certificates
// chain builder must have all certs, including cert to validate
// http://stackoverflow.com/a/10788392
Set<X509Certificate> certs = new HashSet<X509Certificate>();
certs.add(testCert);
certs.addAll(Arrays.asList(additionalCerts));
// Attempt to build the certification chain and verify it
// Create the selector that specifies the starting certificate
X509CertSelector selector = new X509CertSelector();
selector.setCertificate(testCert);
// Create the trust anchors (set of root CA certificates)
Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
for (X509Certificate cert : additionalCerts) {
if (isSelfSigned(cert)) {
trustAnchors.add(new TrustAnchor(cert, null));
}
}
// Configure the PKIX certificate builder
PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(trustAnchors, selector);
pkixParams.setRevocationEnabled(false);
pkixParams.addCertStore(CertStore.getInstance("Collection", new CollectionCertStoreParameters(certs), BC));
// Build and verify the certification chain
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX", BC);
PKIXCertPathBuilderResult verifiedCertChain = (PKIXCertPathBuilderResult) builder.build(pkixParams);
// The chain is built and verified
return verifiedCertChain;
} catch (CertPathBuilderException e) {
throw new RuntimeException("Error building certification path: " + testCert.getSubjectX500Principal(), e);
} catch (Exception e) {
throw new RuntimeException("Error verifying the certificate: " + testCert.getSubjectX500Principal(), e);
}
}
|
java
|
public static PKIXCertPathBuilderResult verifyChain(X509Certificate testCert, X509Certificate... additionalCerts) {
try {
// Check for self-signed certificate
if (isSelfSigned(testCert)) {
throw new RuntimeException("The certificate is self-signed. Nothing to verify.");
}
// Prepare a set of all certificates
// chain builder must have all certs, including cert to validate
// http://stackoverflow.com/a/10788392
Set<X509Certificate> certs = new HashSet<X509Certificate>();
certs.add(testCert);
certs.addAll(Arrays.asList(additionalCerts));
// Attempt to build the certification chain and verify it
// Create the selector that specifies the starting certificate
X509CertSelector selector = new X509CertSelector();
selector.setCertificate(testCert);
// Create the trust anchors (set of root CA certificates)
Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
for (X509Certificate cert : additionalCerts) {
if (isSelfSigned(cert)) {
trustAnchors.add(new TrustAnchor(cert, null));
}
}
// Configure the PKIX certificate builder
PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(trustAnchors, selector);
pkixParams.setRevocationEnabled(false);
pkixParams.addCertStore(CertStore.getInstance("Collection", new CollectionCertStoreParameters(certs), BC));
// Build and verify the certification chain
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX", BC);
PKIXCertPathBuilderResult verifiedCertChain = (PKIXCertPathBuilderResult) builder.build(pkixParams);
// The chain is built and verified
return verifiedCertChain;
} catch (CertPathBuilderException e) {
throw new RuntimeException("Error building certification path: " + testCert.getSubjectX500Principal(), e);
} catch (Exception e) {
throw new RuntimeException("Error verifying the certificate: " + testCert.getSubjectX500Principal(), e);
}
}
|
[
"public",
"static",
"PKIXCertPathBuilderResult",
"verifyChain",
"(",
"X509Certificate",
"testCert",
",",
"X509Certificate",
"...",
"additionalCerts",
")",
"{",
"try",
"{",
"// Check for self-signed certificate",
"if",
"(",
"isSelfSigned",
"(",
"testCert",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The certificate is self-signed. Nothing to verify.\"",
")",
";",
"}",
"// Prepare a set of all certificates",
"// chain builder must have all certs, including cert to validate",
"// http://stackoverflow.com/a/10788392",
"Set",
"<",
"X509Certificate",
">",
"certs",
"=",
"new",
"HashSet",
"<",
"X509Certificate",
">",
"(",
")",
";",
"certs",
".",
"add",
"(",
"testCert",
")",
";",
"certs",
".",
"addAll",
"(",
"Arrays",
".",
"asList",
"(",
"additionalCerts",
")",
")",
";",
"// Attempt to build the certification chain and verify it",
"// Create the selector that specifies the starting certificate",
"X509CertSelector",
"selector",
"=",
"new",
"X509CertSelector",
"(",
")",
";",
"selector",
".",
"setCertificate",
"(",
"testCert",
")",
";",
"// Create the trust anchors (set of root CA certificates)",
"Set",
"<",
"TrustAnchor",
">",
"trustAnchors",
"=",
"new",
"HashSet",
"<",
"TrustAnchor",
">",
"(",
")",
";",
"for",
"(",
"X509Certificate",
"cert",
":",
"additionalCerts",
")",
"{",
"if",
"(",
"isSelfSigned",
"(",
"cert",
")",
")",
"{",
"trustAnchors",
".",
"add",
"(",
"new",
"TrustAnchor",
"(",
"cert",
",",
"null",
")",
")",
";",
"}",
"}",
"// Configure the PKIX certificate builder",
"PKIXBuilderParameters",
"pkixParams",
"=",
"new",
"PKIXBuilderParameters",
"(",
"trustAnchors",
",",
"selector",
")",
";",
"pkixParams",
".",
"setRevocationEnabled",
"(",
"false",
")",
";",
"pkixParams",
".",
"addCertStore",
"(",
"CertStore",
".",
"getInstance",
"(",
"\"Collection\"",
",",
"new",
"CollectionCertStoreParameters",
"(",
"certs",
")",
",",
"BC",
")",
")",
";",
"// Build and verify the certification chain",
"CertPathBuilder",
"builder",
"=",
"CertPathBuilder",
".",
"getInstance",
"(",
"\"PKIX\"",
",",
"BC",
")",
";",
"PKIXCertPathBuilderResult",
"verifiedCertChain",
"=",
"(",
"PKIXCertPathBuilderResult",
")",
"builder",
".",
"build",
"(",
"pkixParams",
")",
";",
"// The chain is built and verified",
"return",
"verifiedCertChain",
";",
"}",
"catch",
"(",
"CertPathBuilderException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Error building certification path: \"",
"+",
"testCert",
".",
"getSubjectX500Principal",
"(",
")",
",",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Error verifying the certificate: \"",
"+",
"testCert",
".",
"getSubjectX500Principal",
"(",
")",
",",
"e",
")",
";",
"}",
"}"
] |
Verifies a certificate's chain to ensure that it will function properly.
@param testCert
@param additionalCerts
@return
|
[
"Verifies",
"a",
"certificate",
"s",
"chain",
"to",
"ensure",
"that",
"it",
"will",
"function",
"properly",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L832-L875
|
10,634
|
gitblit/fathom
|
fathom-x509/src/main/java/fathom/x509/X509Utils.java
|
X509Utils.isSelfSigned
|
public static boolean isSelfSigned(X509Certificate cert) {
try {
cert.verify(cert.getPublicKey());
return true;
} catch (SignatureException e) {
return false;
} catch (InvalidKeyException e) {
return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
java
|
public static boolean isSelfSigned(X509Certificate cert) {
try {
cert.verify(cert.getPublicKey());
return true;
} catch (SignatureException e) {
return false;
} catch (InvalidKeyException e) {
return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"static",
"boolean",
"isSelfSigned",
"(",
"X509Certificate",
"cert",
")",
"{",
"try",
"{",
"cert",
".",
"verify",
"(",
"cert",
".",
"getPublicKey",
"(",
")",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"SignatureException",
"e",
")",
"{",
"return",
"false",
";",
"}",
"catch",
"(",
"InvalidKeyException",
"e",
")",
"{",
"return",
"false",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Checks whether given X.509 certificate is self-signed.
@param cert
@return true if the certificate is self-signed
|
[
"Checks",
"whether",
"given",
"X",
".",
"509",
"certificate",
"is",
"self",
"-",
"signed",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-x509/src/main/java/fathom/x509/X509Utils.java#L883-L894
|
10,635
|
gitblit/fathom
|
fathom-security-htpasswd/src/main/java/fathom/realm/htpasswd/HtpasswdRealm.java
|
HtpasswdRealm.validatePassword
|
@Override
protected boolean validatePassword(StandardCredentials requestCredentials, StandardCredentials storedCredentials) {
final String storedPassword = storedCredentials.getPassword();
final String username = requestCredentials.getUsername();
final String password = requestCredentials.getPassword();
boolean authenticated = false;
// test Apache MD5 variant encrypted password
if (storedPassword.startsWith("$apr1$")) {
if (storedPassword.equals(Md5Crypt.apr1Crypt(password, storedPassword))) {
log.trace("Apache MD5 encoded password matched for user '{}'", username);
authenticated = true;
}
}
// test Unsalted SHA password
else if (storedPassword.startsWith("{SHA}")) {
String password64 = Base64.encodeBase64String(DigestUtils.sha1(password));
if (storedPassword.substring("{SHA}".length()).equals(password64)) {
log.trace("Unsalted SHA-1 encoded password matched for user '{}'", username);
authenticated = true;
}
}
// test Libc Crypt password
else if (!isAllowClearTextPasswords() && storedPassword.equals(Crypt.crypt(password, storedPassword))) {
log.trace("Libc crypt encoded password matched for user '{}'", username);
authenticated = true;
}
// test Clear Text password
else if (isAllowClearTextPasswords() && storedPassword.equals(password)) {
log.trace("Clear text password matched for user '{}'", username);
authenticated = true;
}
return authenticated;
}
|
java
|
@Override
protected boolean validatePassword(StandardCredentials requestCredentials, StandardCredentials storedCredentials) {
final String storedPassword = storedCredentials.getPassword();
final String username = requestCredentials.getUsername();
final String password = requestCredentials.getPassword();
boolean authenticated = false;
// test Apache MD5 variant encrypted password
if (storedPassword.startsWith("$apr1$")) {
if (storedPassword.equals(Md5Crypt.apr1Crypt(password, storedPassword))) {
log.trace("Apache MD5 encoded password matched for user '{}'", username);
authenticated = true;
}
}
// test Unsalted SHA password
else if (storedPassword.startsWith("{SHA}")) {
String password64 = Base64.encodeBase64String(DigestUtils.sha1(password));
if (storedPassword.substring("{SHA}".length()).equals(password64)) {
log.trace("Unsalted SHA-1 encoded password matched for user '{}'", username);
authenticated = true;
}
}
// test Libc Crypt password
else if (!isAllowClearTextPasswords() && storedPassword.equals(Crypt.crypt(password, storedPassword))) {
log.trace("Libc crypt encoded password matched for user '{}'", username);
authenticated = true;
}
// test Clear Text password
else if (isAllowClearTextPasswords() && storedPassword.equals(password)) {
log.trace("Clear text password matched for user '{}'", username);
authenticated = true;
}
return authenticated;
}
|
[
"@",
"Override",
"protected",
"boolean",
"validatePassword",
"(",
"StandardCredentials",
"requestCredentials",
",",
"StandardCredentials",
"storedCredentials",
")",
"{",
"final",
"String",
"storedPassword",
"=",
"storedCredentials",
".",
"getPassword",
"(",
")",
";",
"final",
"String",
"username",
"=",
"requestCredentials",
".",
"getUsername",
"(",
")",
";",
"final",
"String",
"password",
"=",
"requestCredentials",
".",
"getPassword",
"(",
")",
";",
"boolean",
"authenticated",
"=",
"false",
";",
"// test Apache MD5 variant encrypted password",
"if",
"(",
"storedPassword",
".",
"startsWith",
"(",
"\"$apr1$\"",
")",
")",
"{",
"if",
"(",
"storedPassword",
".",
"equals",
"(",
"Md5Crypt",
".",
"apr1Crypt",
"(",
"password",
",",
"storedPassword",
")",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"Apache MD5 encoded password matched for user '{}'\"",
",",
"username",
")",
";",
"authenticated",
"=",
"true",
";",
"}",
"}",
"// test Unsalted SHA password",
"else",
"if",
"(",
"storedPassword",
".",
"startsWith",
"(",
"\"{SHA}\"",
")",
")",
"{",
"String",
"password64",
"=",
"Base64",
".",
"encodeBase64String",
"(",
"DigestUtils",
".",
"sha1",
"(",
"password",
")",
")",
";",
"if",
"(",
"storedPassword",
".",
"substring",
"(",
"\"{SHA}\"",
".",
"length",
"(",
")",
")",
".",
"equals",
"(",
"password64",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"Unsalted SHA-1 encoded password matched for user '{}'\"",
",",
"username",
")",
";",
"authenticated",
"=",
"true",
";",
"}",
"}",
"// test Libc Crypt password",
"else",
"if",
"(",
"!",
"isAllowClearTextPasswords",
"(",
")",
"&&",
"storedPassword",
".",
"equals",
"(",
"Crypt",
".",
"crypt",
"(",
"password",
",",
"storedPassword",
")",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"Libc crypt encoded password matched for user '{}'\"",
",",
"username",
")",
";",
"authenticated",
"=",
"true",
";",
"}",
"// test Clear Text password",
"else",
"if",
"(",
"isAllowClearTextPasswords",
"(",
")",
"&&",
"storedPassword",
".",
"equals",
"(",
"password",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"Clear text password matched for user '{}'\"",
",",
"username",
")",
";",
"authenticated",
"=",
"true",
";",
"}",
"return",
"authenticated",
";",
"}"
] |
htpasswd supports a few other password encryption schemes than the StandardCredentialsRealm.
@param requestCredentials
@param storedCredentials
@return true if the request password validates against the stored password
|
[
"htpasswd",
"supports",
"a",
"few",
"other",
"password",
"encryption",
"schemes",
"than",
"the",
"StandardCredentialsRealm",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-security-htpasswd/src/main/java/fathom/realm/htpasswd/HtpasswdRealm.java#L193-L227
|
10,636
|
gitblit/fathom
|
fathom-security-htpasswd/src/main/java/fathom/realm/htpasswd/HtpasswdRealm.java
|
HtpasswdRealm.readCredentialsFile
|
protected synchronized void readCredentialsFile() {
if (realmFile != null && realmFile.exists() && (realmFile.lastModified() != lastModified)) {
lastModified = realmFile.lastModified();
try {
Map<String, String> credentials = readCredentialsURL(realmFile.toURI().toURL());
credentialsMap.clear();
credentialsMap.putAll(credentials);
} catch (Exception e) {
log.error("Failed to read {}", realmFile, e);
}
}
}
|
java
|
protected synchronized void readCredentialsFile() {
if (realmFile != null && realmFile.exists() && (realmFile.lastModified() != lastModified)) {
lastModified = realmFile.lastModified();
try {
Map<String, String> credentials = readCredentialsURL(realmFile.toURI().toURL());
credentialsMap.clear();
credentialsMap.putAll(credentials);
} catch (Exception e) {
log.error("Failed to read {}", realmFile, e);
}
}
}
|
[
"protected",
"synchronized",
"void",
"readCredentialsFile",
"(",
")",
"{",
"if",
"(",
"realmFile",
"!=",
"null",
"&&",
"realmFile",
".",
"exists",
"(",
")",
"&&",
"(",
"realmFile",
".",
"lastModified",
"(",
")",
"!=",
"lastModified",
")",
")",
"{",
"lastModified",
"=",
"realmFile",
".",
"lastModified",
"(",
")",
";",
"try",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"credentials",
"=",
"readCredentialsURL",
"(",
"realmFile",
".",
"toURI",
"(",
")",
".",
"toURL",
"(",
")",
")",
";",
"credentialsMap",
".",
"clear",
"(",
")",
";",
"credentialsMap",
".",
"putAll",
"(",
"credentials",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to read {}\"",
",",
"realmFile",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Reads the credentials file and rebuilds the in-memory lookup tables.
|
[
"Reads",
"the",
"credentials",
"file",
"and",
"rebuilds",
"the",
"in",
"-",
"memory",
"lookup",
"tables",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-security-htpasswd/src/main/java/fathom/realm/htpasswd/HtpasswdRealm.java#L232-L243
|
10,637
|
gitblit/fathom
|
fathom-security-htpasswd/src/main/java/fathom/realm/htpasswd/HtpasswdRealm.java
|
HtpasswdRealm.readCredentialsURL
|
protected Map<String, String> readCredentialsURL(URL url) {
Map<String, String> credentials = new HashMap<>();
Pattern entry = Pattern.compile("^([^:]+):(.+)");
try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.name())) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (!line.isEmpty() && !line.startsWith("#")) {
Matcher m = entry.matcher(line);
if (m.matches()) {
String username = m.group(1);
String password = m.group(2);
if (Strings.isNullOrEmpty(username)) {
log.warn("Skipping line because the username is blank!");
continue;
}
if (Strings.isNullOrEmpty(password)) {
log.warn("Skipping '{}' account because the password is blank!", username);
continue;
}
credentials.put(username.trim(), password.trim());
}
}
}
} catch (Exception e) {
log.error("Failed to read {}", url, e);
}
return credentials;
}
|
java
|
protected Map<String, String> readCredentialsURL(URL url) {
Map<String, String> credentials = new HashMap<>();
Pattern entry = Pattern.compile("^([^:]+):(.+)");
try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.name())) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (!line.isEmpty() && !line.startsWith("#")) {
Matcher m = entry.matcher(line);
if (m.matches()) {
String username = m.group(1);
String password = m.group(2);
if (Strings.isNullOrEmpty(username)) {
log.warn("Skipping line because the username is blank!");
continue;
}
if (Strings.isNullOrEmpty(password)) {
log.warn("Skipping '{}' account because the password is blank!", username);
continue;
}
credentials.put(username.trim(), password.trim());
}
}
}
} catch (Exception e) {
log.error("Failed to read {}", url, e);
}
return credentials;
}
|
[
"protected",
"Map",
"<",
"String",
",",
"String",
">",
"readCredentialsURL",
"(",
"URL",
"url",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"credentials",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"Pattern",
"entry",
"=",
"Pattern",
".",
"compile",
"(",
"\"^([^:]+):(.+)\"",
")",
";",
"try",
"(",
"Scanner",
"scanner",
"=",
"new",
"Scanner",
"(",
"url",
".",
"openStream",
"(",
")",
",",
"StandardCharsets",
".",
"UTF_8",
".",
"name",
"(",
")",
")",
")",
"{",
"while",
"(",
"scanner",
".",
"hasNextLine",
"(",
")",
")",
"{",
"String",
"line",
"=",
"scanner",
".",
"nextLine",
"(",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"!",
"line",
".",
"isEmpty",
"(",
")",
"&&",
"!",
"line",
".",
"startsWith",
"(",
"\"#\"",
")",
")",
"{",
"Matcher",
"m",
"=",
"entry",
".",
"matcher",
"(",
"line",
")",
";",
"if",
"(",
"m",
".",
"matches",
"(",
")",
")",
"{",
"String",
"username",
"=",
"m",
".",
"group",
"(",
"1",
")",
";",
"String",
"password",
"=",
"m",
".",
"group",
"(",
"2",
")",
";",
"if",
"(",
"Strings",
".",
"isNullOrEmpty",
"(",
"username",
")",
")",
"{",
"log",
".",
"warn",
"(",
"\"Skipping line because the username is blank!\"",
")",
";",
"continue",
";",
"}",
"if",
"(",
"Strings",
".",
"isNullOrEmpty",
"(",
"password",
")",
")",
"{",
"log",
".",
"warn",
"(",
"\"Skipping '{}' account because the password is blank!\"",
",",
"username",
")",
";",
"continue",
";",
"}",
"credentials",
".",
"put",
"(",
"username",
".",
"trim",
"(",
")",
",",
"password",
".",
"trim",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"Failed to read {}\"",
",",
"url",
",",
"e",
")",
";",
"}",
"return",
"credentials",
";",
"}"
] |
Reads the credentials url.
|
[
"Reads",
"the",
"credentials",
"url",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-security-htpasswd/src/main/java/fathom/realm/htpasswd/HtpasswdRealm.java#L248-L276
|
10,638
|
gitblit/fathom
|
fathom-core/src/main/java/fathom/Boot.java
|
Boot.addShutdownHook
|
public Boot addShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Boot.this.stop();
}
});
return this;
}
|
java
|
public Boot addShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Boot.this.stop();
}
});
return this;
}
|
[
"public",
"Boot",
"addShutdownHook",
"(",
")",
"{",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"addShutdownHook",
"(",
"new",
"Thread",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"Boot",
".",
"this",
".",
"stop",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Add a JVM shutdown hook.
|
[
"Add",
"a",
"JVM",
"shutdown",
"hook",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-core/src/main/java/fathom/Boot.java#L156-L167
|
10,639
|
gitblit/fathom
|
fathom-core/src/main/java/fathom/Boot.java
|
Boot.start
|
@Override
public synchronized void start() {
Preconditions.checkNotNull(getServer());
String osName = System.getProperty("os.name");
String osVersion = System.getProperty("os.version");
log.info("Bootstrapping {} ({})", settings.getApplicationName(), settings.getApplicationVersion());
Util.logSetting(log, "Fathom", Constants.getVersion());
Util.logSetting(log, "Mode", settings.getMode().toString());
Util.logSetting(log, "Operating System", String.format("%s (%s)", osName, osVersion));
Util.logSetting(log, "Available processors", Runtime.getRuntime().availableProcessors());
Util.logSetting(log, "Available heap", (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " MB");
SimpleDateFormat df = new SimpleDateFormat("z Z");
df.setTimeZone(TimeZone.getDefault());
String offset = df.format(new Date());
Util.logSetting(log, "JVM timezone", String.format("%s (%s)", TimeZone.getDefault().getID(), offset));
Util.logSetting(log, "JVM locale", Locale.getDefault());
long startTime = System.nanoTime();
getServer().start();
String contextPath = settings.getContextPath();
if (settings.getHttpsPort() > 0) {
log.info("https://{}:{}{}", settings.getHttpsListenAddress(), settings.getHttpsPort(), contextPath);
}
if (settings.getHttpPort() > 0) {
log.info("http://{}:{}{}", settings.getHttpListenAddress(), settings.getHttpPort(), contextPath);
}
if (settings.getAjpPort() > 0) {
log.info("ajp://{}:{}{}", settings.getAjpListenAddress(), settings.getAjpPort(), contextPath);
}
long delta = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
String duration;
if (delta < 1000L) {
duration = String.format("%s ms", delta);
} else {
duration = String.format("%.1f seconds", (delta / 1000f));
}
log.info("Fathom bootstrapped {} mode in {}", settings.getMode().toString(), duration);
log.info("READY.");
}
|
java
|
@Override
public synchronized void start() {
Preconditions.checkNotNull(getServer());
String osName = System.getProperty("os.name");
String osVersion = System.getProperty("os.version");
log.info("Bootstrapping {} ({})", settings.getApplicationName(), settings.getApplicationVersion());
Util.logSetting(log, "Fathom", Constants.getVersion());
Util.logSetting(log, "Mode", settings.getMode().toString());
Util.logSetting(log, "Operating System", String.format("%s (%s)", osName, osVersion));
Util.logSetting(log, "Available processors", Runtime.getRuntime().availableProcessors());
Util.logSetting(log, "Available heap", (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " MB");
SimpleDateFormat df = new SimpleDateFormat("z Z");
df.setTimeZone(TimeZone.getDefault());
String offset = df.format(new Date());
Util.logSetting(log, "JVM timezone", String.format("%s (%s)", TimeZone.getDefault().getID(), offset));
Util.logSetting(log, "JVM locale", Locale.getDefault());
long startTime = System.nanoTime();
getServer().start();
String contextPath = settings.getContextPath();
if (settings.getHttpsPort() > 0) {
log.info("https://{}:{}{}", settings.getHttpsListenAddress(), settings.getHttpsPort(), contextPath);
}
if (settings.getHttpPort() > 0) {
log.info("http://{}:{}{}", settings.getHttpListenAddress(), settings.getHttpPort(), contextPath);
}
if (settings.getAjpPort() > 0) {
log.info("ajp://{}:{}{}", settings.getAjpListenAddress(), settings.getAjpPort(), contextPath);
}
long delta = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
String duration;
if (delta < 1000L) {
duration = String.format("%s ms", delta);
} else {
duration = String.format("%.1f seconds", (delta / 1000f));
}
log.info("Fathom bootstrapped {} mode in {}", settings.getMode().toString(), duration);
log.info("READY.");
}
|
[
"@",
"Override",
"public",
"synchronized",
"void",
"start",
"(",
")",
"{",
"Preconditions",
".",
"checkNotNull",
"(",
"getServer",
"(",
")",
")",
";",
"String",
"osName",
"=",
"System",
".",
"getProperty",
"(",
"\"os.name\"",
")",
";",
"String",
"osVersion",
"=",
"System",
".",
"getProperty",
"(",
"\"os.version\"",
")",
";",
"log",
".",
"info",
"(",
"\"Bootstrapping {} ({})\"",
",",
"settings",
".",
"getApplicationName",
"(",
")",
",",
"settings",
".",
"getApplicationVersion",
"(",
")",
")",
";",
"Util",
".",
"logSetting",
"(",
"log",
",",
"\"Fathom\"",
",",
"Constants",
".",
"getVersion",
"(",
")",
")",
";",
"Util",
".",
"logSetting",
"(",
"log",
",",
"\"Mode\"",
",",
"settings",
".",
"getMode",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"Util",
".",
"logSetting",
"(",
"log",
",",
"\"Operating System\"",
",",
"String",
".",
"format",
"(",
"\"%s (%s)\"",
",",
"osName",
",",
"osVersion",
")",
")",
";",
"Util",
".",
"logSetting",
"(",
"log",
",",
"\"Available processors\"",
",",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"availableProcessors",
"(",
")",
")",
";",
"Util",
".",
"logSetting",
"(",
"log",
",",
"\"Available heap\"",
",",
"(",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"maxMemory",
"(",
")",
"/",
"(",
"1024",
"*",
"1024",
")",
")",
"+",
"\" MB\"",
")",
";",
"SimpleDateFormat",
"df",
"=",
"new",
"SimpleDateFormat",
"(",
"\"z Z\"",
")",
";",
"df",
".",
"setTimeZone",
"(",
"TimeZone",
".",
"getDefault",
"(",
")",
")",
";",
"String",
"offset",
"=",
"df",
".",
"format",
"(",
"new",
"Date",
"(",
")",
")",
";",
"Util",
".",
"logSetting",
"(",
"log",
",",
"\"JVM timezone\"",
",",
"String",
".",
"format",
"(",
"\"%s (%s)\"",
",",
"TimeZone",
".",
"getDefault",
"(",
")",
".",
"getID",
"(",
")",
",",
"offset",
")",
")",
";",
"Util",
".",
"logSetting",
"(",
"log",
",",
"\"JVM locale\"",
",",
"Locale",
".",
"getDefault",
"(",
")",
")",
";",
"long",
"startTime",
"=",
"System",
".",
"nanoTime",
"(",
")",
";",
"getServer",
"(",
")",
".",
"start",
"(",
")",
";",
"String",
"contextPath",
"=",
"settings",
".",
"getContextPath",
"(",
")",
";",
"if",
"(",
"settings",
".",
"getHttpsPort",
"(",
")",
">",
"0",
")",
"{",
"log",
".",
"info",
"(",
"\"https://{}:{}{}\"",
",",
"settings",
".",
"getHttpsListenAddress",
"(",
")",
",",
"settings",
".",
"getHttpsPort",
"(",
")",
",",
"contextPath",
")",
";",
"}",
"if",
"(",
"settings",
".",
"getHttpPort",
"(",
")",
">",
"0",
")",
"{",
"log",
".",
"info",
"(",
"\"http://{}:{}{}\"",
",",
"settings",
".",
"getHttpListenAddress",
"(",
")",
",",
"settings",
".",
"getHttpPort",
"(",
")",
",",
"contextPath",
")",
";",
"}",
"if",
"(",
"settings",
".",
"getAjpPort",
"(",
")",
">",
"0",
")",
"{",
"log",
".",
"info",
"(",
"\"ajp://{}:{}{}\"",
",",
"settings",
".",
"getAjpListenAddress",
"(",
")",
",",
"settings",
".",
"getAjpPort",
"(",
")",
",",
"contextPath",
")",
";",
"}",
"long",
"delta",
"=",
"TimeUnit",
".",
"NANOSECONDS",
".",
"toMillis",
"(",
"System",
".",
"nanoTime",
"(",
")",
"-",
"startTime",
")",
";",
"String",
"duration",
";",
"if",
"(",
"delta",
"<",
"1000L",
")",
"{",
"duration",
"=",
"String",
".",
"format",
"(",
"\"%s ms\"",
",",
"delta",
")",
";",
"}",
"else",
"{",
"duration",
"=",
"String",
".",
"format",
"(",
"\"%.1f seconds\"",
",",
"(",
"delta",
"/",
"1000f",
")",
")",
";",
"}",
"log",
".",
"info",
"(",
"\"Fathom bootstrapped {} mode in {}\"",
",",
"settings",
".",
"getMode",
"(",
")",
".",
"toString",
"(",
")",
",",
"duration",
")",
";",
"log",
".",
"info",
"(",
"\"READY.\"",
")",
";",
"}"
] |
Starts Fathom synchronously.
|
[
"Starts",
"Fathom",
"synchronously",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-core/src/main/java/fathom/Boot.java#L184-L228
|
10,640
|
gitblit/fathom
|
fathom-core/src/main/java/fathom/Boot.java
|
Boot.stop
|
@Override
public synchronized void stop() {
Preconditions.checkNotNull(getServer());
if (getServer().isRunning()) {
try {
log.info("Stopping...");
getServer().stop();
log.info("STOPPED.");
} catch (Exception e) {
Throwable t = Throwables.getRootCause(e);
log.error("Fathom failed on shutdown!", t);
}
}
}
|
java
|
@Override
public synchronized void stop() {
Preconditions.checkNotNull(getServer());
if (getServer().isRunning()) {
try {
log.info("Stopping...");
getServer().stop();
log.info("STOPPED.");
} catch (Exception e) {
Throwable t = Throwables.getRootCause(e);
log.error("Fathom failed on shutdown!", t);
}
}
}
|
[
"@",
"Override",
"public",
"synchronized",
"void",
"stop",
"(",
")",
"{",
"Preconditions",
".",
"checkNotNull",
"(",
"getServer",
"(",
")",
")",
";",
"if",
"(",
"getServer",
"(",
")",
".",
"isRunning",
"(",
")",
")",
"{",
"try",
"{",
"log",
".",
"info",
"(",
"\"Stopping...\"",
")",
";",
"getServer",
"(",
")",
".",
"stop",
"(",
")",
";",
"log",
".",
"info",
"(",
"\"STOPPED.\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"Throwable",
"t",
"=",
"Throwables",
".",
"getRootCause",
"(",
"e",
")",
";",
"log",
".",
"error",
"(",
"\"Fathom failed on shutdown!\"",
",",
"t",
")",
";",
"}",
"}",
"}"
] |
Stops Fathom synchronously.
|
[
"Stops",
"Fathom",
"synchronously",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-core/src/main/java/fathom/Boot.java#L233-L246
|
10,641
|
gitblit/fathom
|
fathom-core/src/main/java/fathom/Boot.java
|
Boot.setupLogback
|
protected void setupLogback() {
// Check for Logback config file System Property
// http://logback.qos.ch/manual/configuration.html
// -Dlogback.configurationFile=logback_prod.xml
if (System.getProperty(LOGBACK_CONFIGURATION_FILE_PROPERTY) != null) {
// Logback already configured
return;
}
// Check for a logback configuration file declared in Fathom settings
URL configFileUrl = settings.getFileUrl(LOGBACK_CONFIGURATION_FILE_PROPERTY, "classpath:conf/logback.xml");
if (configFileUrl == null) {
throw new FathomException("Failed to find Logback config file '{}'",
settings.getString(LOGBACK_CONFIGURATION_FILE_PROPERTY, "classpath:conf/logback.xml"));
}
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
try (InputStream is = configFileUrl.openStream()) {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(is);
log.info("Configured Logback from '{}'", configFileUrl);
} catch (IOException | JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
|
java
|
protected void setupLogback() {
// Check for Logback config file System Property
// http://logback.qos.ch/manual/configuration.html
// -Dlogback.configurationFile=logback_prod.xml
if (System.getProperty(LOGBACK_CONFIGURATION_FILE_PROPERTY) != null) {
// Logback already configured
return;
}
// Check for a logback configuration file declared in Fathom settings
URL configFileUrl = settings.getFileUrl(LOGBACK_CONFIGURATION_FILE_PROPERTY, "classpath:conf/logback.xml");
if (configFileUrl == null) {
throw new FathomException("Failed to find Logback config file '{}'",
settings.getString(LOGBACK_CONFIGURATION_FILE_PROPERTY, "classpath:conf/logback.xml"));
}
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
try (InputStream is = configFileUrl.openStream()) {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
context.reset();
configurator.doConfigure(is);
log.info("Configured Logback from '{}'", configFileUrl);
} catch (IOException | JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
|
[
"protected",
"void",
"setupLogback",
"(",
")",
"{",
"// Check for Logback config file System Property",
"// http://logback.qos.ch/manual/configuration.html",
"// -Dlogback.configurationFile=logback_prod.xml",
"if",
"(",
"System",
".",
"getProperty",
"(",
"LOGBACK_CONFIGURATION_FILE_PROPERTY",
")",
"!=",
"null",
")",
"{",
"// Logback already configured",
"return",
";",
"}",
"// Check for a logback configuration file declared in Fathom settings",
"URL",
"configFileUrl",
"=",
"settings",
".",
"getFileUrl",
"(",
"LOGBACK_CONFIGURATION_FILE_PROPERTY",
",",
"\"classpath:conf/logback.xml\"",
")",
";",
"if",
"(",
"configFileUrl",
"==",
"null",
")",
"{",
"throw",
"new",
"FathomException",
"(",
"\"Failed to find Logback config file '{}'\"",
",",
"settings",
".",
"getString",
"(",
"LOGBACK_CONFIGURATION_FILE_PROPERTY",
",",
"\"classpath:conf/logback.xml\"",
")",
")",
";",
"}",
"LoggerContext",
"context",
"=",
"(",
"LoggerContext",
")",
"LoggerFactory",
".",
"getILoggerFactory",
"(",
")",
";",
"try",
"(",
"InputStream",
"is",
"=",
"configFileUrl",
".",
"openStream",
"(",
")",
")",
"{",
"JoranConfigurator",
"configurator",
"=",
"new",
"JoranConfigurator",
"(",
")",
";",
"configurator",
".",
"setContext",
"(",
"context",
")",
";",
"context",
".",
"reset",
"(",
")",
";",
"configurator",
".",
"doConfigure",
"(",
"is",
")",
";",
"log",
".",
"info",
"(",
"\"Configured Logback from '{}'\"",
",",
"configFileUrl",
")",
";",
"}",
"catch",
"(",
"IOException",
"|",
"JoranException",
"je",
")",
"{",
"// StatusPrinter will handle this",
"}",
"StatusPrinter",
".",
"printInCaseOfErrorsOrWarnings",
"(",
"context",
")",
";",
"}"
] |
Setup Logback logging by optionally reloading the configuration file.
|
[
"Setup",
"Logback",
"logging",
"by",
"optionally",
"reloading",
"the",
"configuration",
"file",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-core/src/main/java/fathom/Boot.java#L259-L290
|
10,642
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/data/AceRights.java
|
AceRights.parseValue
|
public static AceRights parseValue(final int value) {
final AceRights res = new AceRights();
if (value == 0) {
return res;
}
res.others = value;
for (ObjectRight type : ObjectRight.values()) {
if ((value & type.getValue()) == type.getValue()) {
res.rights.add(type);
res.others ^= type.getValue();
}
}
return res;
}
|
java
|
public static AceRights parseValue(final int value) {
final AceRights res = new AceRights();
if (value == 0) {
return res;
}
res.others = value;
for (ObjectRight type : ObjectRight.values()) {
if ((value & type.getValue()) == type.getValue()) {
res.rights.add(type);
res.others ^= type.getValue();
}
}
return res;
}
|
[
"public",
"static",
"AceRights",
"parseValue",
"(",
"final",
"int",
"value",
")",
"{",
"final",
"AceRights",
"res",
"=",
"new",
"AceRights",
"(",
")",
";",
"if",
"(",
"value",
"==",
"0",
")",
"{",
"return",
"res",
";",
"}",
"res",
".",
"others",
"=",
"value",
";",
"for",
"(",
"ObjectRight",
"type",
":",
"ObjectRight",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"(",
"value",
"&",
"type",
".",
"getValue",
"(",
")",
")",
"==",
"type",
".",
"getValue",
"(",
")",
")",
"{",
"res",
".",
"rights",
".",
"add",
"(",
"type",
")",
";",
"res",
".",
"others",
"^=",
"type",
".",
"getValue",
"(",
")",
";",
"}",
"}",
"return",
"res",
";",
"}"
] |
Parse ACE rights.
@param value int value representing rights.
@return ACE rights.
|
[
"Parse",
"ACE",
"rights",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/data/AceRights.java#L198-L214
|
10,643
|
Tirasa/ADSDDL
|
src/main/java/net/tirasa/adsddl/ntsd/data/AceRights.java
|
AceRights.asUInt
|
public long asUInt() {
long res = others;
for (ObjectRight right : rights) {
res += right.getValue();
}
return res;
}
|
java
|
public long asUInt() {
long res = others;
for (ObjectRight right : rights) {
res += right.getValue();
}
return res;
}
|
[
"public",
"long",
"asUInt",
"(",
")",
"{",
"long",
"res",
"=",
"others",
";",
"for",
"(",
"ObjectRight",
"right",
":",
"rights",
")",
"{",
"res",
"+=",
"right",
".",
"getValue",
"(",
")",
";",
"}",
"return",
"res",
";",
"}"
] |
Gets rights as unsigned int.
@return rights as unsigned int.
|
[
"Gets",
"rights",
"as",
"unsigned",
"int",
"."
] |
16dad53e1222c7faa904c64394af94ba18f6d09c
|
https://github.com/Tirasa/ADSDDL/blob/16dad53e1222c7faa904c64394af94ba18f6d09c/src/main/java/net/tirasa/adsddl/ntsd/data/AceRights.java#L261-L269
|
10,644
|
gitblit/fathom
|
fathom-rest/src/main/java/fathom/rest/controller/ControllerUtil.java
|
ControllerUtil.getParameterName
|
public static String getParameterName(Parameter parameter) {
// identify parameter name and pattern from method signature
String methodParameterName = parameter.getName();
if (parameter.isAnnotationPresent(Param.class)) {
Param param = parameter.getAnnotation(Param.class);
if (!Strings.isNullOrEmpty(param.value())) {
methodParameterName = param.value();
}
}
return methodParameterName;
}
|
java
|
public static String getParameterName(Parameter parameter) {
// identify parameter name and pattern from method signature
String methodParameterName = parameter.getName();
if (parameter.isAnnotationPresent(Param.class)) {
Param param = parameter.getAnnotation(Param.class);
if (!Strings.isNullOrEmpty(param.value())) {
methodParameterName = param.value();
}
}
return methodParameterName;
}
|
[
"public",
"static",
"String",
"getParameterName",
"(",
"Parameter",
"parameter",
")",
"{",
"// identify parameter name and pattern from method signature",
"String",
"methodParameterName",
"=",
"parameter",
".",
"getName",
"(",
")",
";",
"if",
"(",
"parameter",
".",
"isAnnotationPresent",
"(",
"Param",
".",
"class",
")",
")",
"{",
"Param",
"param",
"=",
"parameter",
".",
"getAnnotation",
"(",
"Param",
".",
"class",
")",
";",
"if",
"(",
"!",
"Strings",
".",
"isNullOrEmpty",
"(",
"param",
".",
"value",
"(",
")",
")",
")",
"{",
"methodParameterName",
"=",
"param",
".",
"value",
"(",
")",
";",
"}",
"}",
"return",
"methodParameterName",
";",
"}"
] |
Returns the name of a parameter.
@param parameter
@return the name of a parameter.
|
[
"Returns",
"the",
"name",
"of",
"a",
"parameter",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest/src/main/java/fathom/rest/controller/ControllerUtil.java#L113-L123
|
10,645
|
gitblit/fathom
|
fathom-rest/src/main/java/fathom/rest/controller/ControllerUtil.java
|
ControllerUtil.getArgumentExtractor
|
public static Class<? extends ArgumentExtractor> getArgumentExtractor(Parameter parameter) {
for (Annotation annotation : parameter.getAnnotations()) {
if (annotation.annotationType().isAnnotationPresent(ExtractWith.class)) {
ExtractWith with = annotation.annotationType().getAnnotation(ExtractWith.class);
Class<? extends ArgumentExtractor> extractorClass = with.value();
return extractorClass;
}
}
// if unspecified we use the ParamExtractor
return ParamExtractor.class;
}
|
java
|
public static Class<? extends ArgumentExtractor> getArgumentExtractor(Parameter parameter) {
for (Annotation annotation : parameter.getAnnotations()) {
if (annotation.annotationType().isAnnotationPresent(ExtractWith.class)) {
ExtractWith with = annotation.annotationType().getAnnotation(ExtractWith.class);
Class<? extends ArgumentExtractor> extractorClass = with.value();
return extractorClass;
}
}
// if unspecified we use the ParamExtractor
return ParamExtractor.class;
}
|
[
"public",
"static",
"Class",
"<",
"?",
"extends",
"ArgumentExtractor",
">",
"getArgumentExtractor",
"(",
"Parameter",
"parameter",
")",
"{",
"for",
"(",
"Annotation",
"annotation",
":",
"parameter",
".",
"getAnnotations",
"(",
")",
")",
"{",
"if",
"(",
"annotation",
".",
"annotationType",
"(",
")",
".",
"isAnnotationPresent",
"(",
"ExtractWith",
".",
"class",
")",
")",
"{",
"ExtractWith",
"with",
"=",
"annotation",
".",
"annotationType",
"(",
")",
".",
"getAnnotation",
"(",
"ExtractWith",
".",
"class",
")",
";",
"Class",
"<",
"?",
"extends",
"ArgumentExtractor",
">",
"extractorClass",
"=",
"with",
".",
"value",
"(",
")",
";",
"return",
"extractorClass",
";",
"}",
"}",
"// if unspecified we use the ParamExtractor",
"return",
"ParamExtractor",
".",
"class",
";",
"}"
] |
Returns the appropriate ArgumentExtractor to use for the controller method parameter.
@param parameter
@return an argument extractor
|
[
"Returns",
"the",
"appropriate",
"ArgumentExtractor",
"to",
"use",
"for",
"the",
"controller",
"method",
"parameter",
"."
] |
f2f820eb16e9fea1e36ad4eda4ed51b35f056538
|
https://github.com/gitblit/fathom/blob/f2f820eb16e9fea1e36ad4eda4ed51b35f056538/fathom-rest/src/main/java/fathom/rest/controller/ControllerUtil.java#L131-L141
|
10,646
|
michaelwittig/java-q
|
src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorFactory.java
|
QConnectorFactory.create
|
public static QConnectorSync create(final String host, final int port) {
return create(host, port, true, true);
}
|
java
|
public static QConnectorSync create(final String host, final int port) {
return create(host, port, true, true);
}
|
[
"public",
"static",
"QConnectorSync",
"create",
"(",
"final",
"String",
"host",
",",
"final",
"int",
"port",
")",
"{",
"return",
"create",
"(",
"host",
",",
"port",
",",
"true",
",",
"true",
")",
";",
"}"
] |
Reconnect on error and is thread-safe.
@param host Host
@param port Port
@return QConnector
|
[
"Reconnect",
"on",
"error",
"and",
"is",
"thread",
"-",
"safe",
"."
] |
f71fc95b185caa85c6fbdc7179cb4f5f7733b630
|
https://github.com/michaelwittig/java-q/blob/f71fc95b185caa85c6fbdc7179cb4f5f7733b630/src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorFactory.java#L89-L91
|
10,647
|
threerings/playn
|
html/src/playn/html/HtmlPlatform.java
|
HtmlPlatform.register
|
public static HtmlPlatform register(Config config) {
HtmlPlatform platform = new HtmlPlatform(config);
PlayN.setPlatform(platform);
platform.init();
return platform;
}
|
java
|
public static HtmlPlatform register(Config config) {
HtmlPlatform platform = new HtmlPlatform(config);
PlayN.setPlatform(platform);
platform.init();
return platform;
}
|
[
"public",
"static",
"HtmlPlatform",
"register",
"(",
"Config",
"config",
")",
"{",
"HtmlPlatform",
"platform",
"=",
"new",
"HtmlPlatform",
"(",
"config",
")",
";",
"PlayN",
".",
"setPlatform",
"(",
"platform",
")",
";",
"platform",
".",
"init",
"(",
")",
";",
"return",
"platform",
";",
"}"
] |
Prepares the HTML platform for operation.
@param config platform-specific settings.
|
[
"Prepares",
"the",
"HTML",
"platform",
"for",
"operation",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/html/src/playn/html/HtmlPlatform.java#L92-L97
|
10,648
|
threerings/playn
|
core/src/playn/core/gl/GLShader.java
|
GLShader.prepareTexture
|
public GLShader prepareTexture(int tex, int tint) {
// if our GL context has been lost and regained we may need to recreate our core; we don't
// destroy the old core because the underlying resources are gone and destroying using our
// stale handles might result in destroying someone else's newly created resources
if (texEpoch != ctx.epoch()) {
texCore = null;
}
// create our core lazily so that we ensure we're on the GL thread when it happens
if (texCore == null) {
createCore();
}
boolean justActivated = ctx.useShader(this);
if (justActivated) {
texCore.activate(ctx.curFbufWidth, ctx.curFbufHeight);
if (GLContext.STATS_ENABLED) ctx.stats.shaderBinds++;
}
texCore.prepare(tex, tint, justActivated);
return this;
}
|
java
|
public GLShader prepareTexture(int tex, int tint) {
// if our GL context has been lost and regained we may need to recreate our core; we don't
// destroy the old core because the underlying resources are gone and destroying using our
// stale handles might result in destroying someone else's newly created resources
if (texEpoch != ctx.epoch()) {
texCore = null;
}
// create our core lazily so that we ensure we're on the GL thread when it happens
if (texCore == null) {
createCore();
}
boolean justActivated = ctx.useShader(this);
if (justActivated) {
texCore.activate(ctx.curFbufWidth, ctx.curFbufHeight);
if (GLContext.STATS_ENABLED) ctx.stats.shaderBinds++;
}
texCore.prepare(tex, tint, justActivated);
return this;
}
|
[
"public",
"GLShader",
"prepareTexture",
"(",
"int",
"tex",
",",
"int",
"tint",
")",
"{",
"// if our GL context has been lost and regained we may need to recreate our core; we don't",
"// destroy the old core because the underlying resources are gone and destroying using our",
"// stale handles might result in destroying someone else's newly created resources",
"if",
"(",
"texEpoch",
"!=",
"ctx",
".",
"epoch",
"(",
")",
")",
"{",
"texCore",
"=",
"null",
";",
"}",
"// create our core lazily so that we ensure we're on the GL thread when it happens",
"if",
"(",
"texCore",
"==",
"null",
")",
"{",
"createCore",
"(",
")",
";",
"}",
"boolean",
"justActivated",
"=",
"ctx",
".",
"useShader",
"(",
"this",
")",
";",
"if",
"(",
"justActivated",
")",
"{",
"texCore",
".",
"activate",
"(",
"ctx",
".",
"curFbufWidth",
",",
"ctx",
".",
"curFbufHeight",
")",
";",
"if",
"(",
"GLContext",
".",
"STATS_ENABLED",
")",
"ctx",
".",
"stats",
".",
"shaderBinds",
"++",
";",
"}",
"texCore",
".",
"prepare",
"(",
"tex",
",",
"tint",
",",
"justActivated",
")",
";",
"return",
"this",
";",
"}"
] |
Prepares this shader to render the specified texture, etc.
|
[
"Prepares",
"this",
"shader",
"to",
"render",
"the",
"specified",
"texture",
"etc",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/gl/GLShader.java#L115-L133
|
10,649
|
threerings/playn
|
core/src/playn/core/gl/GLShader.java
|
GLShader.addTriangles
|
public void addTriangles(InternalTransform local, float[] xys, int xysOffset, int xysLen,
float tw, float th,
int[] indices, int indicesOffset, int indicesLen, int indexBase) {
texCore.addTriangles(
local.m00(), local.m01(), local.m10(), local.m11(), local.tx(), local.ty(),
xys, xysOffset, xysLen, tw, th, indices, indicesOffset, indicesLen, indexBase);
if (GLContext.STATS_ENABLED) ctx.stats.trisRendered += indicesLen/3;
}
|
java
|
public void addTriangles(InternalTransform local, float[] xys, int xysOffset, int xysLen,
float tw, float th,
int[] indices, int indicesOffset, int indicesLen, int indexBase) {
texCore.addTriangles(
local.m00(), local.m01(), local.m10(), local.m11(), local.tx(), local.ty(),
xys, xysOffset, xysLen, tw, th, indices, indicesOffset, indicesLen, indexBase);
if (GLContext.STATS_ENABLED) ctx.stats.trisRendered += indicesLen/3;
}
|
[
"public",
"void",
"addTriangles",
"(",
"InternalTransform",
"local",
",",
"float",
"[",
"]",
"xys",
",",
"int",
"xysOffset",
",",
"int",
"xysLen",
",",
"float",
"tw",
",",
"float",
"th",
",",
"int",
"[",
"]",
"indices",
",",
"int",
"indicesOffset",
",",
"int",
"indicesLen",
",",
"int",
"indexBase",
")",
"{",
"texCore",
".",
"addTriangles",
"(",
"local",
".",
"m00",
"(",
")",
",",
"local",
".",
"m01",
"(",
")",
",",
"local",
".",
"m10",
"(",
")",
",",
"local",
".",
"m11",
"(",
")",
",",
"local",
".",
"tx",
"(",
")",
",",
"local",
".",
"ty",
"(",
")",
",",
"xys",
",",
"xysOffset",
",",
"xysLen",
",",
"tw",
",",
"th",
",",
"indices",
",",
"indicesOffset",
",",
"indicesLen",
",",
"indexBase",
")",
";",
"if",
"(",
"GLContext",
".",
"STATS_ENABLED",
")",
"ctx",
".",
"stats",
".",
"trisRendered",
"+=",
"indicesLen",
"/",
"3",
";",
"}"
] |
Adds a collection of triangles to the current render operation.
@param xys a list of x/y coordinates as: {@code [x1, y1, x2, y2, ...]}.
@param xysOffset the offset of the coordinates array, must not be negative and no greater than
{@code xys.length}. Note: this is an absolute offset; since {@code xys} contains pairs of
values, this will be some multiple of two.
@param xysLen the number of coordinates to read, must be no less than zero and no greater than
{@code xys.length - xysOffset}. Note: this is an absolute length; since {@code xys} contains
pairs of values, this will be some multiple of two.
@param tw the width of the texture for which we will auto-generate texture coordinates.
@param th the height of the texture for which we will auto-generate texture coordinates.
@param indices the index of the triangle vertices in the {@code xys} array. Because this
method renders a slice of {@code xys}, one must also specify {@code indexBase} which tells us
how to interpret indices. The index into {@code xys} will be computed as:
{@code 2*(indices[ii] - indexBase)}, so if your indices reference vertices relative to the
whole array you should pass {@code xysOffset/2} for {@code indexBase}, but if your indices
reference vertices relative to <em>the slice</em> then you should pass zero.
@param indicesOffset the offset of the indices array, must not be negative and no greater than
{@code indices.length}.
@param indicesLen the number of indices to read, must be no less than zero and no greater than
{@code indices.length - indicesOffset}.
@param indexBase the basis for interpreting {@code indices}. See the docs for {@code indices}
for details.
|
[
"Adds",
"a",
"collection",
"of",
"triangles",
"to",
"the",
"current",
"render",
"operation",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/gl/GLShader.java#L196-L203
|
10,650
|
threerings/playn
|
robovm/src/playn/robovm/RoboPlatform.java
|
RoboPlatform.willRotate
|
void willRotate(UIInterfaceOrientation toOrient, double duration) {
if (orientListener != null) {
orientListener.willRotate(toOrient, duration);
}
}
|
java
|
void willRotate(UIInterfaceOrientation toOrient, double duration) {
if (orientListener != null) {
orientListener.willRotate(toOrient, duration);
}
}
|
[
"void",
"willRotate",
"(",
"UIInterfaceOrientation",
"toOrient",
",",
"double",
"duration",
")",
"{",
"if",
"(",
"orientListener",
"!=",
"null",
")",
"{",
"orientListener",
".",
"willRotate",
"(",
"toOrient",
",",
"duration",
")",
";",
"}",
"}"
] |
with iOS for rotation notifications, game loop callbacks, and app lifecycle events
|
[
"with",
"iOS",
"for",
"rotation",
"notifications",
"game",
"loop",
"callbacks",
"and",
"app",
"lifecycle",
"events"
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/robovm/src/playn/robovm/RoboPlatform.java#L257-L261
|
10,651
|
threerings/playn
|
android/src/playn/android/TouchEventHandler.java
|
TouchEventHandler.parseMotionEvent
|
private Touch.Event.Impl[] parseMotionEvent(MotionEvent event, Events.Flags flags) {
int eventPointerCount = event.getPointerCount();
Touch.Event.Impl[] touches = new Touch.Event.Impl[eventPointerCount];
double time = event.getEventTime();
float pressure, size;
int id;
for (int t = 0; t < eventPointerCount; t++) {
int pointerIndex = t;
IPoint xy = platform.graphics().transformTouch(
event.getX(pointerIndex), event.getY(pointerIndex));
pressure = event.getPressure(pointerIndex);
size = event.getSize(pointerIndex);
id = event.getPointerId(pointerIndex);
touches[t] = new Touch.Event.Impl(flags, time, xy.x(), xy.y(), id, pressure, size);
}
return touches;
}
|
java
|
private Touch.Event.Impl[] parseMotionEvent(MotionEvent event, Events.Flags flags) {
int eventPointerCount = event.getPointerCount();
Touch.Event.Impl[] touches = new Touch.Event.Impl[eventPointerCount];
double time = event.getEventTime();
float pressure, size;
int id;
for (int t = 0; t < eventPointerCount; t++) {
int pointerIndex = t;
IPoint xy = platform.graphics().transformTouch(
event.getX(pointerIndex), event.getY(pointerIndex));
pressure = event.getPressure(pointerIndex);
size = event.getSize(pointerIndex);
id = event.getPointerId(pointerIndex);
touches[t] = new Touch.Event.Impl(flags, time, xy.x(), xy.y(), id, pressure, size);
}
return touches;
}
|
[
"private",
"Touch",
".",
"Event",
".",
"Impl",
"[",
"]",
"parseMotionEvent",
"(",
"MotionEvent",
"event",
",",
"Events",
".",
"Flags",
"flags",
")",
"{",
"int",
"eventPointerCount",
"=",
"event",
".",
"getPointerCount",
"(",
")",
";",
"Touch",
".",
"Event",
".",
"Impl",
"[",
"]",
"touches",
"=",
"new",
"Touch",
".",
"Event",
".",
"Impl",
"[",
"eventPointerCount",
"]",
";",
"double",
"time",
"=",
"event",
".",
"getEventTime",
"(",
")",
";",
"float",
"pressure",
",",
"size",
";",
"int",
"id",
";",
"for",
"(",
"int",
"t",
"=",
"0",
";",
"t",
"<",
"eventPointerCount",
";",
"t",
"++",
")",
"{",
"int",
"pointerIndex",
"=",
"t",
";",
"IPoint",
"xy",
"=",
"platform",
".",
"graphics",
"(",
")",
".",
"transformTouch",
"(",
"event",
".",
"getX",
"(",
"pointerIndex",
")",
",",
"event",
".",
"getY",
"(",
"pointerIndex",
")",
")",
";",
"pressure",
"=",
"event",
".",
"getPressure",
"(",
"pointerIndex",
")",
";",
"size",
"=",
"event",
".",
"getSize",
"(",
"pointerIndex",
")",
";",
"id",
"=",
"event",
".",
"getPointerId",
"(",
"pointerIndex",
")",
";",
"touches",
"[",
"t",
"]",
"=",
"new",
"Touch",
".",
"Event",
".",
"Impl",
"(",
"flags",
",",
"time",
",",
"xy",
".",
"x",
"(",
")",
",",
"xy",
".",
"y",
"(",
")",
",",
"id",
",",
"pressure",
",",
"size",
")",
";",
"}",
"return",
"touches",
";",
"}"
] |
Performs the actual parsing of the MotionEvent event.
@param event The MotionEvent to process
@param preventDefault Shared preventDefault state among returned {@link AndroidTouchEventImpl}
@return Processed array of {@link AndroidTouchEventImpl}s which share a preventDefault state.
|
[
"Performs",
"the",
"actual",
"parsing",
"of",
"the",
"MotionEvent",
"event",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/android/src/playn/android/TouchEventHandler.java#L104-L120
|
10,652
|
threerings/playn
|
core/src/playn/core/Dispatcher.java
|
Dispatcher.dispatch
|
<L, E extends Input.Impl> void dispatch(
AbstractLayer layer, Class<L> listenerType, E event, Interaction<L, E> interaction) {
dispatch(layer, listenerType, event, interaction, null);
}
|
java
|
<L, E extends Input.Impl> void dispatch(
AbstractLayer layer, Class<L> listenerType, E event, Interaction<L, E> interaction) {
dispatch(layer, listenerType, event, interaction, null);
}
|
[
"<",
"L",
",",
"E",
"extends",
"Input",
".",
"Impl",
">",
"void",
"dispatch",
"(",
"AbstractLayer",
"layer",
",",
"Class",
"<",
"L",
">",
"listenerType",
",",
"E",
"event",
",",
"Interaction",
"<",
"L",
",",
"E",
">",
"interaction",
")",
"{",
"dispatch",
"(",
"layer",
",",
"listenerType",
",",
"event",
",",
"interaction",
",",
"null",
")",
";",
"}"
] |
Issues an interact call to a layer and listener with a localized copy of the given event.
|
[
"Issues",
"an",
"interact",
"call",
"to",
"a",
"layer",
"and",
"listener",
"with",
"a",
"localized",
"copy",
"of",
"the",
"given",
"event",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/Dispatcher.java#L191-L194
|
10,653
|
threerings/playn
|
java/src/playn/java/JavaGraphics.java
|
JavaGraphics.setSize
|
public void setSize(int pixelWidth, int pixelHeight, boolean fullscreen) {
setDisplayMode(pixelWidth, pixelHeight, fullscreen);
ctx.setSize(pixelWidth, pixelHeight);
}
|
java
|
public void setSize(int pixelWidth, int pixelHeight, boolean fullscreen) {
setDisplayMode(pixelWidth, pixelHeight, fullscreen);
ctx.setSize(pixelWidth, pixelHeight);
}
|
[
"public",
"void",
"setSize",
"(",
"int",
"pixelWidth",
",",
"int",
"pixelHeight",
",",
"boolean",
"fullscreen",
")",
"{",
"setDisplayMode",
"(",
"pixelWidth",
",",
"pixelHeight",
",",
"fullscreen",
")",
";",
"ctx",
".",
"setSize",
"(",
"pixelWidth",
",",
"pixelHeight",
")",
";",
"}"
] |
Changes the size of the PlayN window.
|
[
"Changes",
"the",
"size",
"of",
"the",
"PlayN",
"window",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/java/src/playn/java/JavaGraphics.java#L94-L97
|
10,654
|
julianhyde/quidem
|
src/main/java/net/hydromatic/quidem/Quidem.java
|
Quidem.main
|
public static void main(String[] args) {
final PrintWriter out = new PrintWriter(System.out);
final PrintWriter err = new PrintWriter(System.err);
final int code = Launcher.main2(out, err, Arrays.asList(args));
System.exit(code);
}
|
java
|
public static void main(String[] args) {
final PrintWriter out = new PrintWriter(System.out);
final PrintWriter err = new PrintWriter(System.err);
final int code = Launcher.main2(out, err, Arrays.asList(args));
System.exit(code);
}
|
[
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"final",
"PrintWriter",
"out",
"=",
"new",
"PrintWriter",
"(",
"System",
".",
"out",
")",
";",
"final",
"PrintWriter",
"err",
"=",
"new",
"PrintWriter",
"(",
"System",
".",
"err",
")",
";",
"final",
"int",
"code",
"=",
"Launcher",
".",
"main2",
"(",
"out",
",",
"err",
",",
"Arrays",
".",
"asList",
"(",
"args",
")",
")",
";",
"System",
".",
"exit",
"(",
"code",
")",
";",
"}"
] |
Entry point from the operating system command line.
<p>Calls {@link System#exit(int)} with the following status codes:
<ul>
<li>0: success</li>
<li>1: invalid arguments</li>
<li>2: help</li>
</ul>
@param args Command-line arguments
|
[
"Entry",
"point",
"from",
"the",
"operating",
"system",
"command",
"line",
"."
] |
43dae9a1a181a03ed877adf5d612255ce2052972
|
https://github.com/julianhyde/quidem/blob/43dae9a1a181a03ed877adf5d612255ce2052972/src/main/java/net/hydromatic/quidem/Quidem.java#L190-L195
|
10,655
|
julianhyde/quidem
|
src/main/java/net/hydromatic/quidem/Quidem.java
|
Quidem.execute
|
public void execute() {
try {
Command command = new Parser().parse();
try {
command.execute(new ContextImpl(), execute);
close();
} catch (Exception e) {
throw new RuntimeException(
"Error while executing command " + command, e);
} catch (AssertionError e) {
throw new RuntimeException(
"Error while executing command " + command, e);
}
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
writer.close();
try {
close();
} catch (SQLException e) {
// ignore
}
}
}
|
java
|
public void execute() {
try {
Command command = new Parser().parse();
try {
command.execute(new ContextImpl(), execute);
close();
} catch (Exception e) {
throw new RuntimeException(
"Error while executing command " + command, e);
} catch (AssertionError e) {
throw new RuntimeException(
"Error while executing command " + command, e);
}
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
writer.close();
try {
close();
} catch (SQLException e) {
// ignore
}
}
}
|
[
"public",
"void",
"execute",
"(",
")",
"{",
"try",
"{",
"Command",
"command",
"=",
"new",
"Parser",
"(",
")",
".",
"parse",
"(",
")",
";",
"try",
"{",
"command",
".",
"execute",
"(",
"new",
"ContextImpl",
"(",
")",
",",
"execute",
")",
";",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Error while executing command \"",
"+",
"command",
",",
"e",
")",
";",
"}",
"catch",
"(",
"AssertionError",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Error while executing command \"",
"+",
"command",
",",
"e",
")",
";",
"}",
"}",
"finally",
"{",
"try",
"{",
"reader",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"writer",
".",
"close",
"(",
")",
";",
"try",
"{",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"// ignore",
"}",
"}",
"}"
] |
Executes the commands from the input, writing to the output,
then closing both input and output.
|
[
"Executes",
"the",
"commands",
"from",
"the",
"input",
"writing",
"to",
"the",
"output",
"then",
"closing",
"both",
"input",
"and",
"output",
"."
] |
43dae9a1a181a03ed877adf5d612255ce2052972
|
https://github.com/julianhyde/quidem/blob/43dae9a1a181a03ed877adf5d612255ce2052972/src/main/java/net/hydromatic/quidem/Quidem.java#L212-L238
|
10,656
|
julianhyde/quidem
|
src/main/java/net/hydromatic/quidem/Quidem.java
|
Quidem.isProbablyDeterministic
|
public boolean isProbablyDeterministic(String sql) {
final String upperSql = sql.toUpperCase();
if (!upperSql.contains("ORDER BY")) {
return false;
}
final int i = upperSql.lastIndexOf("ORDER BY");
final String tail = upperSql.substring(i);
final int closeCount = tail.length() - tail.replace(")", "").length();
final int openCount = tail.length() - tail.replace("(", "").length();
if (closeCount > openCount) {
// The last ORDER BY occurs within parentheses. It is either in a
// sub-query or in a windowed aggregate. Neither of these make the
// ordering deterministic.
return false;
}
return true;
}
|
java
|
public boolean isProbablyDeterministic(String sql) {
final String upperSql = sql.toUpperCase();
if (!upperSql.contains("ORDER BY")) {
return false;
}
final int i = upperSql.lastIndexOf("ORDER BY");
final String tail = upperSql.substring(i);
final int closeCount = tail.length() - tail.replace(")", "").length();
final int openCount = tail.length() - tail.replace("(", "").length();
if (closeCount > openCount) {
// The last ORDER BY occurs within parentheses. It is either in a
// sub-query or in a windowed aggregate. Neither of these make the
// ordering deterministic.
return false;
}
return true;
}
|
[
"public",
"boolean",
"isProbablyDeterministic",
"(",
"String",
"sql",
")",
"{",
"final",
"String",
"upperSql",
"=",
"sql",
".",
"toUpperCase",
"(",
")",
";",
"if",
"(",
"!",
"upperSql",
".",
"contains",
"(",
"\"ORDER BY\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"final",
"int",
"i",
"=",
"upperSql",
".",
"lastIndexOf",
"(",
"\"ORDER BY\"",
")",
";",
"final",
"String",
"tail",
"=",
"upperSql",
".",
"substring",
"(",
"i",
")",
";",
"final",
"int",
"closeCount",
"=",
"tail",
".",
"length",
"(",
")",
"-",
"tail",
".",
"replace",
"(",
"\")\"",
",",
"\"\"",
")",
".",
"length",
"(",
")",
";",
"final",
"int",
"openCount",
"=",
"tail",
".",
"length",
"(",
")",
"-",
"tail",
".",
"replace",
"(",
"\"(\"",
",",
"\"\"",
")",
".",
"length",
"(",
")",
";",
"if",
"(",
"closeCount",
">",
"openCount",
")",
"{",
"// The last ORDER BY occurs within parentheses. It is either in a",
"// sub-query or in a windowed aggregate. Neither of these make the",
"// ordering deterministic.",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Returns whether a SQL query is likely to produce results always in the
same order.
<p>If Quidem believes that the order is deterministic, it does not sort
the rows before comparing them.
<p>The result is just a guess. Quidem does not understand the finer points
of SQL semantics.
@param sql SQL query
@return Whether the order is likely to be deterministic
|
[
"Returns",
"whether",
"a",
"SQL",
"query",
"is",
"likely",
"to",
"produce",
"results",
"always",
"in",
"the",
"same",
"order",
"."
] |
43dae9a1a181a03ed877adf5d612255ce2052972
|
https://github.com/julianhyde/quidem/blob/43dae9a1a181a03ed877adf5d612255ce2052972/src/main/java/net/hydromatic/quidem/Quidem.java#L542-L558
|
10,657
|
julianhyde/quidem
|
src/main/java/net/hydromatic/quidem/Quidem.java
|
Quidem.flush
|
private static String flush(StringBuilder buf) {
final String s = buf.toString();
buf.setLength(0);
return s;
}
|
java
|
private static String flush(StringBuilder buf) {
final String s = buf.toString();
buf.setLength(0);
return s;
}
|
[
"private",
"static",
"String",
"flush",
"(",
"StringBuilder",
"buf",
")",
"{",
"final",
"String",
"s",
"=",
"buf",
".",
"toString",
"(",
")",
";",
"buf",
".",
"setLength",
"(",
"0",
")",
";",
"return",
"s",
";",
"}"
] |
Returns the contents of a StringBuilder and clears it for the next use.
|
[
"Returns",
"the",
"contents",
"of",
"a",
"StringBuilder",
"and",
"clears",
"it",
"for",
"the",
"next",
"use",
"."
] |
43dae9a1a181a03ed877adf5d612255ce2052972
|
https://github.com/julianhyde/quidem/blob/43dae9a1a181a03ed877adf5d612255ce2052972/src/main/java/net/hydromatic/quidem/Quidem.java#L1032-L1036
|
10,658
|
threerings/playn
|
core/src/playn/core/gl/ImageGL.java
|
ImageGL.createPow2RepTex
|
protected int createPow2RepTex(int width, int height, boolean repeatX, boolean repeatY,
boolean mipmapped) {
int powtex = ctx.createTexture(width, height, repeatX, repeatY, mipmapped);
updateTexture(powtex);
return powtex;
}
|
java
|
protected int createPow2RepTex(int width, int height, boolean repeatX, boolean repeatY,
boolean mipmapped) {
int powtex = ctx.createTexture(width, height, repeatX, repeatY, mipmapped);
updateTexture(powtex);
return powtex;
}
|
[
"protected",
"int",
"createPow2RepTex",
"(",
"int",
"width",
",",
"int",
"height",
",",
"boolean",
"repeatX",
",",
"boolean",
"repeatY",
",",
"boolean",
"mipmapped",
")",
"{",
"int",
"powtex",
"=",
"ctx",
".",
"createTexture",
"(",
"width",
",",
"height",
",",
"repeatX",
",",
"repeatY",
",",
"mipmapped",
")",
";",
"updateTexture",
"(",
"powtex",
")",
";",
"return",
"powtex",
";",
"}"
] |
Creates and populates a texture for use as our power-of-two texture. This is used when our
main image data is already power-of-two-sized.
|
[
"Creates",
"and",
"populates",
"a",
"texture",
"for",
"use",
"as",
"our",
"power",
"-",
"of",
"-",
"two",
"texture",
".",
"This",
"is",
"used",
"when",
"our",
"main",
"image",
"data",
"is",
"already",
"power",
"-",
"of",
"-",
"two",
"-",
"sized",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/gl/ImageGL.java#L87-L92
|
10,659
|
iovation/launchkey-java
|
sdk/src/main/java/com/iovation/launchkey/sdk/crypto/JCECrypto.java
|
JCECrypto.getRSAPrivateKeyFromPEM
|
public static RSAPrivateKey getRSAPrivateKeyFromPEM(Provider provider, String pem) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA", provider);
return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(getKeyBytesFromPEM(pem)));
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("Algorithm SHA256withRSA is not available", e);
} catch (InvalidKeySpecException e) {
throw new IllegalArgumentException("Invalid PEM provided", e);
}
}
|
java
|
public static RSAPrivateKey getRSAPrivateKeyFromPEM(Provider provider, String pem) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA", provider);
return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(getKeyBytesFromPEM(pem)));
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("Algorithm SHA256withRSA is not available", e);
} catch (InvalidKeySpecException e) {
throw new IllegalArgumentException("Invalid PEM provided", e);
}
}
|
[
"public",
"static",
"RSAPrivateKey",
"getRSAPrivateKeyFromPEM",
"(",
"Provider",
"provider",
",",
"String",
"pem",
")",
"{",
"try",
"{",
"KeyFactory",
"keyFactory",
"=",
"KeyFactory",
".",
"getInstance",
"(",
"\"RSA\"",
",",
"provider",
")",
";",
"return",
"(",
"RSAPrivateKey",
")",
"keyFactory",
".",
"generatePrivate",
"(",
"new",
"PKCS8EncodedKeySpec",
"(",
"getKeyBytesFromPEM",
"(",
"pem",
")",
")",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Algorithm SHA256withRSA is not available\"",
",",
"e",
")",
";",
"}",
"catch",
"(",
"InvalidKeySpecException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid PEM provided\"",
",",
"e",
")",
";",
"}",
"}"
] |
Get an RSA private key utilizing the provided provider and PEM formatted string
@param provider Provider to generate the key
@param pem PEM formatted key string
@return RSA private key
|
[
"Get",
"an",
"RSA",
"private",
"key",
"utilizing",
"the",
"provided",
"provider",
"and",
"PEM",
"formatted",
"string"
] |
ceecc70b9b04af07ddc14c57d4bcc933a4e0379c
|
https://github.com/iovation/launchkey-java/blob/ceecc70b9b04af07ddc14c57d4bcc933a4e0379c/sdk/src/main/java/com/iovation/launchkey/sdk/crypto/JCECrypto.java#L96-L105
|
10,660
|
iovation/launchkey-java
|
sdk/src/main/java/com/iovation/launchkey/sdk/crypto/JCECrypto.java
|
JCECrypto.getRSAPublicKeyFromPEM
|
public static RSAPublicKey getRSAPublicKeyFromPEM(Provider provider, String pem) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA", provider);
return (RSAPublicKey) keyFactory.generatePublic(new X509EncodedKeySpec(getKeyBytesFromPEM(pem)));
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("Algorithm SHA256withRSA is not available", e);
} catch (InvalidKeySpecException e) {
throw new IllegalArgumentException("Invalid PEM provided", e);
}
}
|
java
|
public static RSAPublicKey getRSAPublicKeyFromPEM(Provider provider, String pem) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA", provider);
return (RSAPublicKey) keyFactory.generatePublic(new X509EncodedKeySpec(getKeyBytesFromPEM(pem)));
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException("Algorithm SHA256withRSA is not available", e);
} catch (InvalidKeySpecException e) {
throw new IllegalArgumentException("Invalid PEM provided", e);
}
}
|
[
"public",
"static",
"RSAPublicKey",
"getRSAPublicKeyFromPEM",
"(",
"Provider",
"provider",
",",
"String",
"pem",
")",
"{",
"try",
"{",
"KeyFactory",
"keyFactory",
"=",
"KeyFactory",
".",
"getInstance",
"(",
"\"RSA\"",
",",
"provider",
")",
";",
"return",
"(",
"RSAPublicKey",
")",
"keyFactory",
".",
"generatePublic",
"(",
"new",
"X509EncodedKeySpec",
"(",
"getKeyBytesFromPEM",
"(",
"pem",
")",
")",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Algorithm SHA256withRSA is not available\"",
",",
"e",
")",
";",
"}",
"catch",
"(",
"InvalidKeySpecException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid PEM provided\"",
",",
"e",
")",
";",
"}",
"}"
] |
Get an RSA public key utilizing the provided provider and PEM formatted string
@param provider Provider to generate the key
@param pem PEM formatted key string
@return RSA public key
|
[
"Get",
"an",
"RSA",
"public",
"key",
"utilizing",
"the",
"provided",
"provider",
"and",
"PEM",
"formatted",
"string"
] |
ceecc70b9b04af07ddc14c57d4bcc933a4e0379c
|
https://github.com/iovation/launchkey-java/blob/ceecc70b9b04af07ddc14c57d4bcc933a4e0379c/sdk/src/main/java/com/iovation/launchkey/sdk/crypto/JCECrypto.java#L114-L123
|
10,661
|
iovation/launchkey-java
|
sdk/src/main/java/com/iovation/launchkey/sdk/crypto/JCECrypto.java
|
JCECrypto.getPEMFromRSAPublicKey
|
public static String getPEMFromRSAPublicKey(RSAPublicKey publicKey) {
StringBuilder builder = new StringBuilder();
builder.append("-----BEGIN PUBLIC KEY-----\n");
String encoded = new String(BASE_64.encode(publicKey.getEncoded()));
int start = 0;
int end = 64;
try {
//noinspection InfiniteLoopStatement
while (true) {
builder.append(encoded.substring(start, end));
builder.append("\n");
start = end;
end = start + 64;
}
} catch (IndexOutOfBoundsException e) {
if (start != encoded.length()) {
builder.append(encoded.substring(start, encoded.length()));
builder.append("\n");
}
}
builder.append("-----END PUBLIC KEY-----\n");
return builder.toString();
}
|
java
|
public static String getPEMFromRSAPublicKey(RSAPublicKey publicKey) {
StringBuilder builder = new StringBuilder();
builder.append("-----BEGIN PUBLIC KEY-----\n");
String encoded = new String(BASE_64.encode(publicKey.getEncoded()));
int start = 0;
int end = 64;
try {
//noinspection InfiniteLoopStatement
while (true) {
builder.append(encoded.substring(start, end));
builder.append("\n");
start = end;
end = start + 64;
}
} catch (IndexOutOfBoundsException e) {
if (start != encoded.length()) {
builder.append(encoded.substring(start, encoded.length()));
builder.append("\n");
}
}
builder.append("-----END PUBLIC KEY-----\n");
return builder.toString();
}
|
[
"public",
"static",
"String",
"getPEMFromRSAPublicKey",
"(",
"RSAPublicKey",
"publicKey",
")",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"builder",
".",
"append",
"(",
"\"-----BEGIN PUBLIC KEY-----\\n\"",
")",
";",
"String",
"encoded",
"=",
"new",
"String",
"(",
"BASE_64",
".",
"encode",
"(",
"publicKey",
".",
"getEncoded",
"(",
")",
")",
")",
";",
"int",
"start",
"=",
"0",
";",
"int",
"end",
"=",
"64",
";",
"try",
"{",
"//noinspection InfiniteLoopStatement",
"while",
"(",
"true",
")",
"{",
"builder",
".",
"append",
"(",
"encoded",
".",
"substring",
"(",
"start",
",",
"end",
")",
")",
";",
"builder",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"start",
"=",
"end",
";",
"end",
"=",
"start",
"+",
"64",
";",
"}",
"}",
"catch",
"(",
"IndexOutOfBoundsException",
"e",
")",
"{",
"if",
"(",
"start",
"!=",
"encoded",
".",
"length",
"(",
")",
")",
"{",
"builder",
".",
"append",
"(",
"encoded",
".",
"substring",
"(",
"start",
",",
"encoded",
".",
"length",
"(",
")",
")",
")",
";",
"builder",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"}",
"}",
"builder",
".",
"append",
"(",
"\"-----END PUBLIC KEY-----\\n\"",
")",
";",
"return",
"builder",
".",
"toString",
"(",
")",
";",
"}"
] |
Get a PEM formatted string from the provided public key
@param publicKey RSA Public Key object
@return PEM formatted public key string
|
[
"Get",
"a",
"PEM",
"formatted",
"string",
"from",
"the",
"provided",
"public",
"key"
] |
ceecc70b9b04af07ddc14c57d4bcc933a4e0379c
|
https://github.com/iovation/launchkey-java/blob/ceecc70b9b04af07ddc14c57d4bcc933a4e0379c/sdk/src/main/java/com/iovation/launchkey/sdk/crypto/JCECrypto.java#L164-L189
|
10,662
|
iovation/launchkey-java
|
sdk/src/main/java/com/iovation/launchkey/sdk/FactoryFactoryBuilder.java
|
FactoryFactoryBuilder.build
|
public FactoryFactory build() {
return new FactoryFactory(
getJceProvider(),
getHttpClient(),
getKeyCache(),
getApiBaseURL(),
getApiIdentifier(),
getRequestExpireSeconds(),
offsetTTL,
currentPublicKeyTTL,
entityKeyMap
);
}
|
java
|
public FactoryFactory build() {
return new FactoryFactory(
getJceProvider(),
getHttpClient(),
getKeyCache(),
getApiBaseURL(),
getApiIdentifier(),
getRequestExpireSeconds(),
offsetTTL,
currentPublicKeyTTL,
entityKeyMap
);
}
|
[
"public",
"FactoryFactory",
"build",
"(",
")",
"{",
"return",
"new",
"FactoryFactory",
"(",
"getJceProvider",
"(",
")",
",",
"getHttpClient",
"(",
")",
",",
"getKeyCache",
"(",
")",
",",
"getApiBaseURL",
"(",
")",
",",
"getApiIdentifier",
"(",
")",
",",
"getRequestExpireSeconds",
"(",
")",
",",
"offsetTTL",
",",
"currentPublicKeyTTL",
",",
"entityKeyMap",
")",
";",
"}"
] |
Build a factory based on the currently configured information
@return Client Factory Factory
|
[
"Build",
"a",
"factory",
"based",
"on",
"the",
"currently",
"configured",
"information"
] |
ceecc70b9b04af07ddc14c57d4bcc933a4e0379c
|
https://github.com/iovation/launchkey-java/blob/ceecc70b9b04af07ddc14c57d4bcc933a4e0379c/sdk/src/main/java/com/iovation/launchkey/sdk/FactoryFactoryBuilder.java#L55-L68
|
10,663
|
michaelwittig/java-q
|
src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorAsyncImpl.java
|
QConnectorAsyncImpl.throwQException
|
private void throwQException(final QConnectorException e) {
this.executor.execute(new Runnable() {
@Override
public void run() {
QConnectorAsyncImpl.this.listener.exception(e);
}
});
}
|
java
|
private void throwQException(final QConnectorException e) {
this.executor.execute(new Runnable() {
@Override
public void run() {
QConnectorAsyncImpl.this.listener.exception(e);
}
});
}
|
[
"private",
"void",
"throwQException",
"(",
"final",
"QConnectorException",
"e",
")",
"{",
"this",
".",
"executor",
".",
"execute",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"QConnectorAsyncImpl",
".",
"this",
".",
"listener",
".",
"exception",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Throw an exception if something happened, that the system can not fix.
@param e Exception
|
[
"Throw",
"an",
"exception",
"if",
"something",
"happened",
"that",
"the",
"system",
"can",
"not",
"fix",
"."
] |
f71fc95b185caa85c6fbdc7179cb4f5f7733b630
|
https://github.com/michaelwittig/java-q/blob/f71fc95b185caa85c6fbdc7179cb4f5f7733b630/src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorAsyncImpl.java#L207-L215
|
10,664
|
michaelwittig/java-q
|
src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorAsyncImpl.java
|
QConnectorAsyncImpl.throwQError
|
private void throwQError(final QConnectorError e) {
this.executor.execute(new Runnable() {
@Override
public void run() {
QConnectorAsyncImpl.this.listener.error(e);
}
});
}
|
java
|
private void throwQError(final QConnectorError e) {
this.executor.execute(new Runnable() {
@Override
public void run() {
QConnectorAsyncImpl.this.listener.error(e);
}
});
}
|
[
"private",
"void",
"throwQError",
"(",
"final",
"QConnectorError",
"e",
")",
"{",
"this",
".",
"executor",
".",
"execute",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"QConnectorAsyncImpl",
".",
"this",
".",
"listener",
".",
"error",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Throw an error if something happened, that the system can fix on his own, but is might important to know.
@param e Error
|
[
"Throw",
"an",
"error",
"if",
"something",
"happened",
"that",
"the",
"system",
"can",
"fix",
"on",
"his",
"own",
"but",
"is",
"might",
"important",
"to",
"know",
"."
] |
f71fc95b185caa85c6fbdc7179cb4f5f7733b630
|
https://github.com/michaelwittig/java-q/blob/f71fc95b185caa85c6fbdc7179cb4f5f7733b630/src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorAsyncImpl.java#L222-L230
|
10,665
|
michaelwittig/java-q
|
src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorAsyncImpl.java
|
QConnectorAsyncImpl.throwResult
|
private void throwResult(final Result result) {
this.executor.execute(new Runnable() {
@Override
public void run() {
QConnectorAsyncImpl.this.listener.resultReceived("", result);
}
});
}
|
java
|
private void throwResult(final Result result) {
this.executor.execute(new Runnable() {
@Override
public void run() {
QConnectorAsyncImpl.this.listener.resultReceived("", result);
}
});
}
|
[
"private",
"void",
"throwResult",
"(",
"final",
"Result",
"result",
")",
"{",
"this",
".",
"executor",
".",
"execute",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"QConnectorAsyncImpl",
".",
"this",
".",
"listener",
".",
"resultReceived",
"(",
"\"\"",
",",
"result",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Throw result.
@param result Result
|
[
"Throw",
"result",
"."
] |
f71fc95b185caa85c6fbdc7179cb4f5f7733b630
|
https://github.com/michaelwittig/java-q/blob/f71fc95b185caa85c6fbdc7179cb4f5f7733b630/src/main/java/info/michaelwittig/javaq/connector/impl/QConnectorAsyncImpl.java#L237-L245
|
10,666
|
threerings/playn
|
core/src/playn/core/GroupLayerImpl.java
|
GroupLayerImpl.findChild
|
private int findChild(L child, float depth) {
// findInsertion will find us some element with the same depth as the to-be-removed child
int startIdx = findInsertion(depth);
// search down for our child
for (int ii = startIdx-1; ii >= 0; ii--) {
L c = children.get(ii);
if (c == child) {
return ii;
}
if (c.depth() != depth) {
break;
}
}
// search up for our child
for (int ii = startIdx, ll = children.size(); ii < ll; ii++) {
L c = children.get(ii);
if (c == child) {
return ii;
}
if (c.depth() != depth) {
break;
}
}
return -1;
}
|
java
|
private int findChild(L child, float depth) {
// findInsertion will find us some element with the same depth as the to-be-removed child
int startIdx = findInsertion(depth);
// search down for our child
for (int ii = startIdx-1; ii >= 0; ii--) {
L c = children.get(ii);
if (c == child) {
return ii;
}
if (c.depth() != depth) {
break;
}
}
// search up for our child
for (int ii = startIdx, ll = children.size(); ii < ll; ii++) {
L c = children.get(ii);
if (c == child) {
return ii;
}
if (c.depth() != depth) {
break;
}
}
return -1;
}
|
[
"private",
"int",
"findChild",
"(",
"L",
"child",
",",
"float",
"depth",
")",
"{",
"// findInsertion will find us some element with the same depth as the to-be-removed child",
"int",
"startIdx",
"=",
"findInsertion",
"(",
"depth",
")",
";",
"// search down for our child",
"for",
"(",
"int",
"ii",
"=",
"startIdx",
"-",
"1",
";",
"ii",
">=",
"0",
";",
"ii",
"--",
")",
"{",
"L",
"c",
"=",
"children",
".",
"get",
"(",
"ii",
")",
";",
"if",
"(",
"c",
"==",
"child",
")",
"{",
"return",
"ii",
";",
"}",
"if",
"(",
"c",
".",
"depth",
"(",
")",
"!=",
"depth",
")",
"{",
"break",
";",
"}",
"}",
"// search up for our child",
"for",
"(",
"int",
"ii",
"=",
"startIdx",
",",
"ll",
"=",
"children",
".",
"size",
"(",
")",
";",
"ii",
"<",
"ll",
";",
"ii",
"++",
")",
"{",
"L",
"c",
"=",
"children",
".",
"get",
"(",
"ii",
")",
";",
"if",
"(",
"c",
"==",
"child",
")",
"{",
"return",
"ii",
";",
"}",
"if",
"(",
"c",
".",
"depth",
"(",
")",
"!=",
"depth",
")",
"{",
"break",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
uses depth to improve upon a full linear search
|
[
"uses",
"depth",
"to",
"improve",
"upon",
"a",
"full",
"linear",
"search"
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/GroupLayerImpl.java#L181-L205
|
10,667
|
threerings/playn
|
core/src/playn/core/GroupLayerImpl.java
|
GroupLayerImpl.findInsertion
|
private int findInsertion(float depth) {
int low = 0, high = children.size()-1;
while (low <= high) {
int mid = (low + high) >>> 1;
float midDepth = children.get(mid).depth();
if (depth > midDepth) {
low = mid + 1;
} else if (depth < midDepth) {
high = mid - 1;
} else {
return mid;
}
}
return low;
}
|
java
|
private int findInsertion(float depth) {
int low = 0, high = children.size()-1;
while (low <= high) {
int mid = (low + high) >>> 1;
float midDepth = children.get(mid).depth();
if (depth > midDepth) {
low = mid + 1;
} else if (depth < midDepth) {
high = mid - 1;
} else {
return mid;
}
}
return low;
}
|
[
"private",
"int",
"findInsertion",
"(",
"float",
"depth",
")",
"{",
"int",
"low",
"=",
"0",
",",
"high",
"=",
"children",
".",
"size",
"(",
")",
"-",
"1",
";",
"while",
"(",
"low",
"<=",
"high",
")",
"{",
"int",
"mid",
"=",
"(",
"low",
"+",
"high",
")",
">>>",
"1",
";",
"float",
"midDepth",
"=",
"children",
".",
"get",
"(",
"mid",
")",
".",
"depth",
"(",
")",
";",
"if",
"(",
"depth",
">",
"midDepth",
")",
"{",
"low",
"=",
"mid",
"+",
"1",
";",
"}",
"else",
"if",
"(",
"depth",
"<",
"midDepth",
")",
"{",
"high",
"=",
"mid",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"mid",
";",
"}",
"}",
"return",
"low",
";",
"}"
] |
who says you never have to write binary search?
|
[
"who",
"says",
"you",
"never",
"have",
"to",
"write",
"binary",
"search?"
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/GroupLayerImpl.java#L208-L222
|
10,668
|
threerings/playn
|
core/src/playn/core/gl/AbstractImageGL.java
|
AbstractImageGL.draw
|
void draw(GLShader shader, InternalTransform xform, int tint,
float dx, float dy, float dw, float dh) {
draw(shader, xform, tint, dx, dy, dw, dh,
0, 0, (repeatX ? dw : width()), (repeatY ? dh : height()));
}
|
java
|
void draw(GLShader shader, InternalTransform xform, int tint,
float dx, float dy, float dw, float dh) {
draw(shader, xform, tint, dx, dy, dw, dh,
0, 0, (repeatX ? dw : width()), (repeatY ? dh : height()));
}
|
[
"void",
"draw",
"(",
"GLShader",
"shader",
",",
"InternalTransform",
"xform",
",",
"int",
"tint",
",",
"float",
"dx",
",",
"float",
"dy",
",",
"float",
"dw",
",",
"float",
"dh",
")",
"{",
"draw",
"(",
"shader",
",",
"xform",
",",
"tint",
",",
"dx",
",",
"dy",
",",
"dw",
",",
"dh",
",",
"0",
",",
"0",
",",
"(",
"repeatX",
"?",
"dw",
":",
"width",
"(",
")",
")",
",",
"(",
"repeatY",
"?",
"dh",
":",
"height",
"(",
")",
")",
")",
";",
"}"
] |
Draws this image with the supplied transform in the specified target dimensions.
|
[
"Draws",
"this",
"image",
"with",
"the",
"supplied",
"transform",
"in",
"the",
"specified",
"target",
"dimensions",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/gl/AbstractImageGL.java#L67-L71
|
10,669
|
threerings/playn
|
core/src/playn/core/gl/AbstractImageGL.java
|
AbstractImageGL.draw
|
void draw(GLShader shader, InternalTransform xform, int tint,
float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) {
float texWidth = width(), texHeight = height();
drawImpl(shader, xform, ensureTexture(), tint, dx, dy, dw, dh,
sx / texWidth, sy / texHeight, (sx + sw) / texWidth, (sy + sh) / texHeight);
}
|
java
|
void draw(GLShader shader, InternalTransform xform, int tint,
float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) {
float texWidth = width(), texHeight = height();
drawImpl(shader, xform, ensureTexture(), tint, dx, dy, dw, dh,
sx / texWidth, sy / texHeight, (sx + sw) / texWidth, (sy + sh) / texHeight);
}
|
[
"void",
"draw",
"(",
"GLShader",
"shader",
",",
"InternalTransform",
"xform",
",",
"int",
"tint",
",",
"float",
"dx",
",",
"float",
"dy",
",",
"float",
"dw",
",",
"float",
"dh",
",",
"float",
"sx",
",",
"float",
"sy",
",",
"float",
"sw",
",",
"float",
"sh",
")",
"{",
"float",
"texWidth",
"=",
"width",
"(",
")",
",",
"texHeight",
"=",
"height",
"(",
")",
";",
"drawImpl",
"(",
"shader",
",",
"xform",
",",
"ensureTexture",
"(",
")",
",",
"tint",
",",
"dx",
",",
"dy",
",",
"dw",
",",
"dh",
",",
"sx",
"/",
"texWidth",
",",
"sy",
"/",
"texHeight",
",",
"(",
"sx",
"+",
"sw",
")",
"/",
"texWidth",
",",
"(",
"sy",
"+",
"sh",
")",
"/",
"texHeight",
")",
";",
"}"
] |
Draws this image with the supplied transform, and source and target dimensions.
|
[
"Draws",
"this",
"image",
"with",
"the",
"supplied",
"transform",
"and",
"source",
"and",
"target",
"dimensions",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/gl/AbstractImageGL.java#L76-L81
|
10,670
|
julianhyde/quidem
|
src/main/java/net/hydromatic/quidem/Launcher.java
|
Launcher.main2
|
static int main2(PrintWriter out, PrintWriter err, List<String> args) {
try {
final Launcher launcher = new Launcher(args, out);
final Quidem quidem;
try {
quidem = launcher.parse();
} catch (ParseException e) {
return e.code;
}
quidem.execute();
return 0;
} catch (Throwable e) {
out.flush();
e.printStackTrace(err);
return 2;
} finally {
out.flush();
err.flush();
}
}
|
java
|
static int main2(PrintWriter out, PrintWriter err, List<String> args) {
try {
final Launcher launcher = new Launcher(args, out);
final Quidem quidem;
try {
quidem = launcher.parse();
} catch (ParseException e) {
return e.code;
}
quidem.execute();
return 0;
} catch (Throwable e) {
out.flush();
e.printStackTrace(err);
return 2;
} finally {
out.flush();
err.flush();
}
}
|
[
"static",
"int",
"main2",
"(",
"PrintWriter",
"out",
",",
"PrintWriter",
"err",
",",
"List",
"<",
"String",
">",
"args",
")",
"{",
"try",
"{",
"final",
"Launcher",
"launcher",
"=",
"new",
"Launcher",
"(",
"args",
",",
"out",
")",
";",
"final",
"Quidem",
"quidem",
";",
"try",
"{",
"quidem",
"=",
"launcher",
".",
"parse",
"(",
")",
";",
"}",
"catch",
"(",
"ParseException",
"e",
")",
"{",
"return",
"e",
".",
"code",
";",
"}",
"quidem",
".",
"execute",
"(",
")",
";",
"return",
"0",
";",
"}",
"catch",
"(",
"Throwable",
"e",
")",
"{",
"out",
".",
"flush",
"(",
")",
";",
"e",
".",
"printStackTrace",
"(",
"err",
")",
";",
"return",
"2",
";",
"}",
"finally",
"{",
"out",
".",
"flush",
"(",
")",
";",
"err",
".",
"flush",
"(",
")",
";",
"}",
"}"
] |
Creates a launcher, parses command line arguments, and runs Quidem.
<p>Similar to a {@code main} method, but never calls
{@link System#exit(int)}.
@param out Writer to which to print output
@param args Command-line arguments
@return Operating system error code (0 = success, 1 = invalid arguments,
2 = other error)
|
[
"Creates",
"a",
"launcher",
"parses",
"command",
"line",
"arguments",
"and",
"runs",
"Quidem",
"."
] |
43dae9a1a181a03ed877adf5d612255ce2052972
|
https://github.com/julianhyde/quidem/blob/43dae9a1a181a03ed877adf5d612255ce2052972/src/main/java/net/hydromatic/quidem/Launcher.java#L75-L94
|
10,671
|
julianhyde/quidem
|
src/main/java/net/hydromatic/quidem/LimitWriter.java
|
LimitWriter.ellipsis
|
public void ellipsis(String message) {
if (length >= maxLength) {
try {
out.write(message);
out.flush();
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
}
|
java
|
public void ellipsis(String message) {
if (length >= maxLength) {
try {
out.write(message);
out.flush();
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
}
|
[
"public",
"void",
"ellipsis",
"(",
"String",
"message",
")",
"{",
"if",
"(",
"length",
">=",
"maxLength",
")",
"{",
"try",
"{",
"out",
".",
"write",
"(",
"message",
")",
";",
"out",
".",
"flush",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"Throwables",
".",
"propagate",
"(",
"e",
")",
";",
"}",
"}",
"}"
] |
Appends a message if the limit has been reached or exceeded.
|
[
"Appends",
"a",
"message",
"if",
"the",
"limit",
"has",
"been",
"reached",
"or",
"exceeded",
"."
] |
43dae9a1a181a03ed877adf5d612255ce2052972
|
https://github.com/julianhyde/quidem/blob/43dae9a1a181a03ed877adf5d612255ce2052972/src/main/java/net/hydromatic/quidem/LimitWriter.java#L75-L84
|
10,672
|
threerings/playn
|
html/src/playn/html/HtmlGraphics.java
|
HtmlGraphics.setSize
|
public void setSize(int width, int height) {
rootElement.getStyle().setWidth(width, Unit.PX);
rootElement.getStyle().setHeight(height, Unit.PX);
}
|
java
|
public void setSize(int width, int height) {
rootElement.getStyle().setWidth(width, Unit.PX);
rootElement.getStyle().setHeight(height, Unit.PX);
}
|
[
"public",
"void",
"setSize",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"rootElement",
".",
"getStyle",
"(",
")",
".",
"setWidth",
"(",
"width",
",",
"Unit",
".",
"PX",
")",
";",
"rootElement",
".",
"getStyle",
"(",
")",
".",
"setHeight",
"(",
"height",
",",
"Unit",
".",
"PX",
")",
";",
"}"
] |
Sizes or resizes the root element that contains the PlayN view.
@param width the new width, in pixels, of the view.
@param height the new height, in pixels, of the view.
|
[
"Sizes",
"or",
"resizes",
"the",
"root",
"element",
"that",
"contains",
"the",
"PlayN",
"view",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/html/src/playn/html/HtmlGraphics.java#L83-L86
|
10,673
|
threerings/playn
|
html/src/playn/html/HtmlInternalTransform.java
|
HtmlInternalTransform.uniformScale
|
@Override
public float uniformScale() {
// the square root of the signed area of the parallelogram spanned by the axis vectors
float cp = m00() * m11() - m01() * m10();
return (cp < 0f) ? -FloatMath.sqrt(-cp) : FloatMath.sqrt(cp);
}
|
java
|
@Override
public float uniformScale() {
// the square root of the signed area of the parallelogram spanned by the axis vectors
float cp = m00() * m11() - m01() * m10();
return (cp < 0f) ? -FloatMath.sqrt(-cp) : FloatMath.sqrt(cp);
}
|
[
"@",
"Override",
"public",
"float",
"uniformScale",
"(",
")",
"{",
"// the square root of the signed area of the parallelogram spanned by the axis vectors",
"float",
"cp",
"=",
"m00",
"(",
")",
"*",
"m11",
"(",
")",
"-",
"m01",
"(",
")",
"*",
"m10",
"(",
")",
";",
"return",
"(",
"cp",
"<",
"0f",
")",
"?",
"-",
"FloatMath",
".",
"sqrt",
"(",
"-",
"cp",
")",
":",
"FloatMath",
".",
"sqrt",
"(",
"cp",
")",
";",
"}"
] |
Pythagoras Transform implementation
|
[
"Pythagoras",
"Transform",
"implementation"
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/html/src/playn/html/HtmlInternalTransform.java#L44-L49
|
10,674
|
threerings/playn
|
ios/src/playn/ios/IOSGL20.java
|
IOSGL20.createHandle
|
private static GCHandle createHandle (Buffer buffer)
{
Object array;
if (buffer instanceof ByteBuffer)
array = ((ByteBuffer)buffer).array();
else if (buffer instanceof ShortBuffer)
array = ((ShortBuffer)buffer).array();
else if (buffer instanceof IntBuffer)
array = ((IntBuffer)buffer).array();
else if (buffer instanceof FloatBuffer)
array = ((FloatBuffer)buffer).array();
else if (buffer instanceof DoubleBuffer)
array = ((DoubleBuffer)buffer).array();
else
throw new IllegalArgumentException();
return GCHandle.Alloc(array, GCHandleType.wrap(GCHandleType.Pinned));
}
|
java
|
private static GCHandle createHandle (Buffer buffer)
{
Object array;
if (buffer instanceof ByteBuffer)
array = ((ByteBuffer)buffer).array();
else if (buffer instanceof ShortBuffer)
array = ((ShortBuffer)buffer).array();
else if (buffer instanceof IntBuffer)
array = ((IntBuffer)buffer).array();
else if (buffer instanceof FloatBuffer)
array = ((FloatBuffer)buffer).array();
else if (buffer instanceof DoubleBuffer)
array = ((DoubleBuffer)buffer).array();
else
throw new IllegalArgumentException();
return GCHandle.Alloc(array, GCHandleType.wrap(GCHandleType.Pinned));
}
|
[
"private",
"static",
"GCHandle",
"createHandle",
"(",
"Buffer",
"buffer",
")",
"{",
"Object",
"array",
";",
"if",
"(",
"buffer",
"instanceof",
"ByteBuffer",
")",
"array",
"=",
"(",
"(",
"ByteBuffer",
")",
"buffer",
")",
".",
"array",
"(",
")",
";",
"else",
"if",
"(",
"buffer",
"instanceof",
"ShortBuffer",
")",
"array",
"=",
"(",
"(",
"ShortBuffer",
")",
"buffer",
")",
".",
"array",
"(",
")",
";",
"else",
"if",
"(",
"buffer",
"instanceof",
"IntBuffer",
")",
"array",
"=",
"(",
"(",
"IntBuffer",
")",
"buffer",
")",
".",
"array",
"(",
")",
";",
"else",
"if",
"(",
"buffer",
"instanceof",
"FloatBuffer",
")",
"array",
"=",
"(",
"(",
"FloatBuffer",
")",
"buffer",
")",
".",
"array",
"(",
")",
";",
"else",
"if",
"(",
"buffer",
"instanceof",
"DoubleBuffer",
")",
"array",
"=",
"(",
"(",
"DoubleBuffer",
")",
"buffer",
")",
".",
"array",
"(",
")",
";",
"else",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"return",
"GCHandle",
".",
"Alloc",
"(",
"array",
",",
"GCHandleType",
".",
"wrap",
"(",
"GCHandleType",
".",
"Pinned",
")",
")",
";",
"}"
] |
Allocates a pinned GCHandle pointing at a buffer's data. Remember to free it!
|
[
"Allocates",
"a",
"pinned",
"GCHandle",
"pointing",
"at",
"a",
"buffer",
"s",
"data",
".",
"Remember",
"to",
"free",
"it!"
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/ios/src/playn/ios/IOSGL20.java#L1483-L1499
|
10,675
|
threerings/playn
|
core/src/playn/core/util/CallbackList.java
|
CallbackList.create
|
public static <T> CallbackList<T> create(Callback<T> callback) {
CallbackList<T> list = new CallbackList<T>();
list.add(callback);
return list;
}
|
java
|
public static <T> CallbackList<T> create(Callback<T> callback) {
CallbackList<T> list = new CallbackList<T>();
list.add(callback);
return list;
}
|
[
"public",
"static",
"<",
"T",
">",
"CallbackList",
"<",
"T",
">",
"create",
"(",
"Callback",
"<",
"T",
">",
"callback",
")",
"{",
"CallbackList",
"<",
"T",
">",
"list",
"=",
"new",
"CallbackList",
"<",
"T",
">",
"(",
")",
";",
"list",
".",
"add",
"(",
"callback",
")",
";",
"return",
"list",
";",
"}"
] |
Creates a callback list, populated with the supplied callback.
|
[
"Creates",
"a",
"callback",
"list",
"populated",
"with",
"the",
"supplied",
"callback",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/util/CallbackList.java#L33-L37
|
10,676
|
threerings/playn
|
core/src/playn/core/util/CallbackList.java
|
CallbackList.add
|
public CallbackList<T> add(Callback<T> callback) {
checkState();
callbacks.add(callback);
return this;
}
|
java
|
public CallbackList<T> add(Callback<T> callback) {
checkState();
callbacks.add(callback);
return this;
}
|
[
"public",
"CallbackList",
"<",
"T",
">",
"add",
"(",
"Callback",
"<",
"T",
">",
"callback",
")",
"{",
"checkState",
"(",
")",
";",
"callbacks",
".",
"add",
"(",
"callback",
")",
";",
"return",
"this",
";",
"}"
] |
Adds the supplied callback to the list.
@return this instance for convenient chaining.
@throws IllegalStateException if this callback has already fired.
|
[
"Adds",
"the",
"supplied",
"callback",
"to",
"the",
"list",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/util/CallbackList.java#L45-L49
|
10,677
|
threerings/playn
|
core/src/playn/core/util/CallbackList.java
|
CallbackList.onSuccess
|
@Override
public void onSuccess(T result) {
checkState();
for (Callback<T> cb : callbacks) {
cb.onSuccess(result);
}
callbacks = null; // note that we've fired
}
|
java
|
@Override
public void onSuccess(T result) {
checkState();
for (Callback<T> cb : callbacks) {
cb.onSuccess(result);
}
callbacks = null; // note that we've fired
}
|
[
"@",
"Override",
"public",
"void",
"onSuccess",
"(",
"T",
"result",
")",
"{",
"checkState",
"(",
")",
";",
"for",
"(",
"Callback",
"<",
"T",
">",
"cb",
":",
"callbacks",
")",
"{",
"cb",
".",
"onSuccess",
"(",
"result",
")",
";",
"}",
"callbacks",
"=",
"null",
";",
"// note that we've fired",
"}"
] |
Dispatches success to all of the callbacks registered with this list. This may only be called
once.
@throws IllegalStateException if this callback has already fired.
|
[
"Dispatches",
"success",
"to",
"all",
"of",
"the",
"callbacks",
"registered",
"with",
"this",
"list",
".",
"This",
"may",
"only",
"be",
"called",
"once",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/util/CallbackList.java#L67-L74
|
10,678
|
threerings/playn
|
core/src/playn/core/util/CallbackList.java
|
CallbackList.onFailure
|
@Override
public void onFailure(Throwable cause) {
checkState();
for (Callback<T> cb : callbacks) {
cb.onFailure(cause);
}
callbacks = null; // note that we've fired
}
|
java
|
@Override
public void onFailure(Throwable cause) {
checkState();
for (Callback<T> cb : callbacks) {
cb.onFailure(cause);
}
callbacks = null; // note that we've fired
}
|
[
"@",
"Override",
"public",
"void",
"onFailure",
"(",
"Throwable",
"cause",
")",
"{",
"checkState",
"(",
")",
";",
"for",
"(",
"Callback",
"<",
"T",
">",
"cb",
":",
"callbacks",
")",
"{",
"cb",
".",
"onFailure",
"(",
"cause",
")",
";",
"}",
"callbacks",
"=",
"null",
";",
"// note that we've fired",
"}"
] |
Dispatches failure to all of the callbacks registered with this list. This may only be called
once.
@throws IllegalStateException if this callback has already fired.
|
[
"Dispatches",
"failure",
"to",
"all",
"of",
"the",
"callbacks",
"registered",
"with",
"this",
"list",
".",
"This",
"may",
"only",
"be",
"called",
"once",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/util/CallbackList.java#L82-L89
|
10,679
|
threerings/playn
|
html/src/playn/html/HtmlInput.java
|
HtmlInput.captureEvent
|
static void captureEvent(final Element elem, String eventName, final EventHandler handler) {
// register regular event handler on the element
HtmlPlatform.captureEvent(elem, eventName, handler);
}
|
java
|
static void captureEvent(final Element elem, String eventName, final EventHandler handler) {
// register regular event handler on the element
HtmlPlatform.captureEvent(elem, eventName, handler);
}
|
[
"static",
"void",
"captureEvent",
"(",
"final",
"Element",
"elem",
",",
"String",
"eventName",
",",
"final",
"EventHandler",
"handler",
")",
"{",
"// register regular event handler on the element",
"HtmlPlatform",
".",
"captureEvent",
"(",
"elem",
",",
"eventName",
",",
"handler",
")",
";",
"}"
] |
Capture events that occur on the target element only.
|
[
"Capture",
"events",
"that",
"occur",
"on",
"the",
"target",
"element",
"only",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/html/src/playn/html/HtmlInput.java#L47-L50
|
10,680
|
threerings/playn
|
java/src/playn/java/JavaPlatform.java
|
JavaPlatform.register
|
public static JavaPlatform register(Config config) {
// guard against multiple-registration (only in headless mode because this can happen when
// running tests in Maven; in non-headless mode, we want to fail rather than silently ignore
// erroneous repeated registration)
if (config.headless && testInstance != null) {
return testInstance;
}
JavaPlatform instance = new JavaPlatform(config);
if (config.headless) {
testInstance = instance;
}
PlayN.setPlatform(instance);
return instance;
}
|
java
|
public static JavaPlatform register(Config config) {
// guard against multiple-registration (only in headless mode because this can happen when
// running tests in Maven; in non-headless mode, we want to fail rather than silently ignore
// erroneous repeated registration)
if (config.headless && testInstance != null) {
return testInstance;
}
JavaPlatform instance = new JavaPlatform(config);
if (config.headless) {
testInstance = instance;
}
PlayN.setPlatform(instance);
return instance;
}
|
[
"public",
"static",
"JavaPlatform",
"register",
"(",
"Config",
"config",
")",
"{",
"// guard against multiple-registration (only in headless mode because this can happen when",
"// running tests in Maven; in non-headless mode, we want to fail rather than silently ignore",
"// erroneous repeated registration)",
"if",
"(",
"config",
".",
"headless",
"&&",
"testInstance",
"!=",
"null",
")",
"{",
"return",
"testInstance",
";",
"}",
"JavaPlatform",
"instance",
"=",
"new",
"JavaPlatform",
"(",
"config",
")",
";",
"if",
"(",
"config",
".",
"headless",
")",
"{",
"testInstance",
"=",
"instance",
";",
"}",
"PlayN",
".",
"setPlatform",
"(",
"instance",
")",
";",
"return",
"instance",
";",
"}"
] |
Registers the Java platform with the specified configuration.
|
[
"Registers",
"the",
"Java",
"platform",
"with",
"the",
"specified",
"configuration",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/java/src/playn/java/JavaPlatform.java#L104-L117
|
10,681
|
Drivemode/TypefaceHelper
|
TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceCache.java
|
TypefaceCache.get
|
public synchronized Typeface get(String name) {
Typeface typeface = mCache.get(name);
if(typeface == null) {
try {
typeface = Typeface.createFromAsset(mApplication.getAssets(), name);
} catch (Exception exp) {
return null;
}
mCache.put(name, typeface);
}
return typeface;
}
|
java
|
public synchronized Typeface get(String name) {
Typeface typeface = mCache.get(name);
if(typeface == null) {
try {
typeface = Typeface.createFromAsset(mApplication.getAssets(), name);
} catch (Exception exp) {
return null;
}
mCache.put(name, typeface);
}
return typeface;
}
|
[
"public",
"synchronized",
"Typeface",
"get",
"(",
"String",
"name",
")",
"{",
"Typeface",
"typeface",
"=",
"mCache",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"typeface",
"==",
"null",
")",
"{",
"try",
"{",
"typeface",
"=",
"Typeface",
".",
"createFromAsset",
"(",
"mApplication",
".",
"getAssets",
"(",
")",
",",
"name",
")",
";",
"}",
"catch",
"(",
"Exception",
"exp",
")",
"{",
"return",
"null",
";",
"}",
"mCache",
".",
"put",
"(",
"name",
",",
"typeface",
")",
";",
"}",
"return",
"typeface",
";",
"}"
] |
If the cache has an instance for the typeface name, this will return the instance immediately.
Otherwise this method will create typeface instance and put it into the cache and return the instance.
@param name the typeface name.
@return {@link android.graphics.Typeface} instance.
|
[
"If",
"the",
"cache",
"has",
"an",
"instance",
"for",
"the",
"typeface",
"name",
"this",
"will",
"return",
"the",
"instance",
"immediately",
".",
"Otherwise",
"this",
"method",
"will",
"create",
"typeface",
"instance",
"and",
"put",
"it",
"into",
"the",
"cache",
"and",
"return",
"the",
"instance",
"."
] |
86bef9ce16b9626b7076559e846db1b9f043c008
|
https://github.com/Drivemode/TypefaceHelper/blob/86bef9ce16b9626b7076559e846db1b9f043c008/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceCache.java#L34-L45
|
10,682
|
Drivemode/TypefaceHelper
|
TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceCache.java
|
TypefaceCache.getInstance
|
public static synchronized TypefaceCache getInstance(Context context) {
if (sInstance == null)
sInstance = new TypefaceCache((Application)context.getApplicationContext());
return sInstance;
}
|
java
|
public static synchronized TypefaceCache getInstance(Context context) {
if (sInstance == null)
sInstance = new TypefaceCache((Application)context.getApplicationContext());
return sInstance;
}
|
[
"public",
"static",
"synchronized",
"TypefaceCache",
"getInstance",
"(",
"Context",
"context",
")",
"{",
"if",
"(",
"sInstance",
"==",
"null",
")",
"sInstance",
"=",
"new",
"TypefaceCache",
"(",
"(",
"Application",
")",
"context",
".",
"getApplicationContext",
"(",
")",
")",
";",
"return",
"sInstance",
";",
"}"
] |
Retrieve this cache.
@param context the context.
@return the cache instance.
|
[
"Retrieve",
"this",
"cache",
"."
] |
86bef9ce16b9626b7076559e846db1b9f043c008
|
https://github.com/Drivemode/TypefaceHelper/blob/86bef9ce16b9626b7076559e846db1b9f043c008/TypefaceHelper/src/main/java/com/drivemode/android/typeface/TypefaceCache.java#L52-L56
|
10,683
|
threerings/playn
|
ios/src/playn/ios/IOSPlatform.java
|
IOSPlatform.register
|
public static IOSPlatform register(UIApplication app, Config config) {
return register(app, null, config);
}
|
java
|
public static IOSPlatform register(UIApplication app, Config config) {
return register(app, null, config);
}
|
[
"public",
"static",
"IOSPlatform",
"register",
"(",
"UIApplication",
"app",
",",
"Config",
"config",
")",
"{",
"return",
"register",
"(",
"app",
",",
"null",
",",
"config",
")",
";",
"}"
] |
Registers your application using the supplied configuration.
|
[
"Registers",
"your",
"application",
"using",
"the",
"supplied",
"configuration",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/ios/src/playn/ios/IOSPlatform.java#L164-L166
|
10,684
|
threerings/playn
|
ios/src/playn/ios/IOSPlatform.java
|
IOSPlatform.register
|
public static IOSPlatform register(UIApplication app, UIWindow window, Config config) {
IOSPlatform platform = new IOSPlatform(app, window, config);
PlayN.setPlatform(platform);
return platform;
}
|
java
|
public static IOSPlatform register(UIApplication app, UIWindow window, Config config) {
IOSPlatform platform = new IOSPlatform(app, window, config);
PlayN.setPlatform(platform);
return platform;
}
|
[
"public",
"static",
"IOSPlatform",
"register",
"(",
"UIApplication",
"app",
",",
"UIWindow",
"window",
",",
"Config",
"config",
")",
"{",
"IOSPlatform",
"platform",
"=",
"new",
"IOSPlatform",
"(",
"app",
",",
"window",
",",
"config",
")",
";",
"PlayN",
".",
"setPlatform",
"(",
"platform",
")",
";",
"return",
"platform",
";",
"}"
] |
Registers your application using the supplied configuration and window.
The window is used for a game integrated as a part of application. An iOS application
typically just works on one screen so that the game has to share the window created by other
controllers (typically created by the story board). If no window is specified, the platform
will create one taking over the whole application.
Note that PlayN will still install a RootViewController on the supplied UIWindow. If a custom
root view controller is needed, your application should subclass {@link IOSRootViewController}
or replicate its functionality in your root view controller.
|
[
"Registers",
"your",
"application",
"using",
"the",
"supplied",
"configuration",
"and",
"window",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/ios/src/playn/ios/IOSPlatform.java#L180-L184
|
10,685
|
threerings/playn
|
core/src/playn/core/gl/GLContext.java
|
GLContext.useShader
|
public boolean useShader(GLShader shader) {
if (curShader == shader)
return false;
checkGLError("useShader");
flush(true);
curShader = shader;
return true;
}
|
java
|
public boolean useShader(GLShader shader) {
if (curShader == shader)
return false;
checkGLError("useShader");
flush(true);
curShader = shader;
return true;
}
|
[
"public",
"boolean",
"useShader",
"(",
"GLShader",
"shader",
")",
"{",
"if",
"(",
"curShader",
"==",
"shader",
")",
"return",
"false",
";",
"checkGLError",
"(",
"\"useShader\"",
")",
";",
"flush",
"(",
"true",
")",
";",
"curShader",
"=",
"shader",
";",
"return",
"true",
";",
"}"
] |
Makes the supplied shader the current shader, flushing any previous shader.
|
[
"Makes",
"the",
"supplied",
"shader",
"the",
"current",
"shader",
"flushing",
"any",
"previous",
"shader",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/gl/GLContext.java#L307-L314
|
10,686
|
threerings/playn
|
core/src/playn/core/AbstractLayer.java
|
AbstractLayer.interact
|
private <L, E> void interact(Class<L> type, Interaction<L, E> interaction,
Interactor<?> current, E argument) {
if (current == null)
return;
interact(type, interaction, current.next, argument);
if (current.listenerType == type) {
@SuppressWarnings("unchecked") L listener = (L)current.listener;
interaction.interact(listener, argument);
}
}
|
java
|
private <L, E> void interact(Class<L> type, Interaction<L, E> interaction,
Interactor<?> current, E argument) {
if (current == null)
return;
interact(type, interaction, current.next, argument);
if (current.listenerType == type) {
@SuppressWarnings("unchecked") L listener = (L)current.listener;
interaction.interact(listener, argument);
}
}
|
[
"private",
"<",
"L",
",",
"E",
">",
"void",
"interact",
"(",
"Class",
"<",
"L",
">",
"type",
",",
"Interaction",
"<",
"L",
",",
"E",
">",
"interaction",
",",
"Interactor",
"<",
"?",
">",
"current",
",",
"E",
"argument",
")",
"{",
"if",
"(",
"current",
"==",
"null",
")",
"return",
";",
"interact",
"(",
"type",
",",
"interaction",
",",
"current",
".",
"next",
",",
"argument",
")",
";",
"if",
"(",
"current",
".",
"listenerType",
"==",
"type",
")",
"{",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"L",
"listener",
"=",
"(",
"L",
")",
"current",
".",
"listener",
";",
"interaction",
".",
"interact",
"(",
"listener",
",",
"argument",
")",
";",
"}",
"}"
] |
neither affects, nor conflicts with, the current dispatch
|
[
"neither",
"affects",
"nor",
"conflicts",
"with",
"the",
"current",
"dispatch"
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/AbstractLayer.java#L385-L394
|
10,687
|
threerings/playn
|
html/src/playn/super/java/nio/LongBuffer.java
|
LongBuffer.compareTo
|
public int compareTo (LongBuffer otherBuffer) {
int compareRemaining = (remaining() < otherBuffer.remaining()) ?
remaining() : otherBuffer.remaining();
int thisPos = position;
int otherPos = otherBuffer.position;
// BEGIN android-changed
long thisLong, otherLong;
while (compareRemaining > 0) {
thisLong = get(thisPos);
otherLong = otherBuffer.get(otherPos);
if (thisLong != otherLong) {
return thisLong < otherLong ? -1 : 1;
}
thisPos++;
otherPos++;
compareRemaining--;
}
// END android-changed
return remaining() - otherBuffer.remaining();
}
|
java
|
public int compareTo (LongBuffer otherBuffer) {
int compareRemaining = (remaining() < otherBuffer.remaining()) ?
remaining() : otherBuffer.remaining();
int thisPos = position;
int otherPos = otherBuffer.position;
// BEGIN android-changed
long thisLong, otherLong;
while (compareRemaining > 0) {
thisLong = get(thisPos);
otherLong = otherBuffer.get(otherPos);
if (thisLong != otherLong) {
return thisLong < otherLong ? -1 : 1;
}
thisPos++;
otherPos++;
compareRemaining--;
}
// END android-changed
return remaining() - otherBuffer.remaining();
}
|
[
"public",
"int",
"compareTo",
"(",
"LongBuffer",
"otherBuffer",
")",
"{",
"int",
"compareRemaining",
"=",
"(",
"remaining",
"(",
")",
"<",
"otherBuffer",
".",
"remaining",
"(",
")",
")",
"?",
"remaining",
"(",
")",
":",
"otherBuffer",
".",
"remaining",
"(",
")",
";",
"int",
"thisPos",
"=",
"position",
";",
"int",
"otherPos",
"=",
"otherBuffer",
".",
"position",
";",
"// BEGIN android-changed",
"long",
"thisLong",
",",
"otherLong",
";",
"while",
"(",
"compareRemaining",
">",
"0",
")",
"{",
"thisLong",
"=",
"get",
"(",
"thisPos",
")",
";",
"otherLong",
"=",
"otherBuffer",
".",
"get",
"(",
"otherPos",
")",
";",
"if",
"(",
"thisLong",
"!=",
"otherLong",
")",
"{",
"return",
"thisLong",
"<",
"otherLong",
"?",
"-",
"1",
":",
"1",
";",
"}",
"thisPos",
"++",
";",
"otherPos",
"++",
";",
"compareRemaining",
"--",
";",
"}",
"// END android-changed",
"return",
"remaining",
"(",
")",
"-",
"otherBuffer",
".",
"remaining",
"(",
")",
";",
"}"
] |
Compare the remaining longs of this buffer to another long buffer's remaining longs.
@param otherBuffer another long buffer.
@return a negative value if this is less than {@code otherBuffer}; 0 if this equals to
{@code otherBuffer}; a positive value if this is greater than {@code otherBuffer}
@exception ClassCastException if {@code otherBuffer} is not a long buffer.
|
[
"Compare",
"the",
"remaining",
"longs",
"of",
"this",
"buffer",
"to",
"another",
"long",
"buffer",
"s",
"remaining",
"longs",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/html/src/playn/super/java/nio/LongBuffer.java#L107-L126
|
10,688
|
michaelwittig/java-q
|
src/main/java/info/michaelwittig/javaq/connector/impl/CResultHelper.java
|
CResultHelper.convert
|
public static Result convert(final Object res) throws QConnectorException {
if (res == null) {
return new EmptyResult();
}
// table
if (res instanceof c.Flip) {
return new FlipResult("", (c.Flip) res);
}
// dict
if (res instanceof c.Dict) {
final c.Dict dict = (c.Dict) res;
if ((dict.x instanceof c.Flip) && (dict.y instanceof c.Flip)) {
final c.Flip key = (c.Flip) dict.x;
final c.Flip data = (c.Flip) dict.y;
return new FlipFlipResult("", key, data);
}
}
if (res instanceof Object[]) {
final Object[] oa = (Object[]) res;
if ((oa.length == 2) && (oa[0] instanceof String) && (oa[1] instanceof c.Flip)) {
final String table = (String) oa[0];
final c.Flip flip = (c.Flip) oa[1];
return new FlipResult(table, flip);
} else if ((oa.length == 3) && (oa[1] instanceof String) && (oa[2] instanceof c.Flip)) {
final String table = (String) oa[1];
final c.Flip flip = (c.Flip) oa[2];
return new FlipResult(table, flip);
} else {
return new ListResult<Object>(oa);
}
}
// list
if (res instanceof byte[]) {
return new ListResult<Byte>(ArrayUtils.toObject((byte[]) res));
}
|
java
|
public static Result convert(final Object res) throws QConnectorException {
if (res == null) {
return new EmptyResult();
}
// table
if (res instanceof c.Flip) {
return new FlipResult("", (c.Flip) res);
}
// dict
if (res instanceof c.Dict) {
final c.Dict dict = (c.Dict) res;
if ((dict.x instanceof c.Flip) && (dict.y instanceof c.Flip)) {
final c.Flip key = (c.Flip) dict.x;
final c.Flip data = (c.Flip) dict.y;
return new FlipFlipResult("", key, data);
}
}
if (res instanceof Object[]) {
final Object[] oa = (Object[]) res;
if ((oa.length == 2) && (oa[0] instanceof String) && (oa[1] instanceof c.Flip)) {
final String table = (String) oa[0];
final c.Flip flip = (c.Flip) oa[1];
return new FlipResult(table, flip);
} else if ((oa.length == 3) && (oa[1] instanceof String) && (oa[2] instanceof c.Flip)) {
final String table = (String) oa[1];
final c.Flip flip = (c.Flip) oa[2];
return new FlipResult(table, flip);
} else {
return new ListResult<Object>(oa);
}
}
// list
if (res instanceof byte[]) {
return new ListResult<Byte>(ArrayUtils.toObject((byte[]) res));
}
|
[
"public",
"static",
"Result",
"convert",
"(",
"final",
"Object",
"res",
")",
"throws",
"QConnectorException",
"{",
"if",
"(",
"res",
"==",
"null",
")",
"{",
"return",
"new",
"EmptyResult",
"(",
")",
";",
"}",
"// table",
"if",
"(",
"res",
"instanceof",
"c",
".",
"Flip",
")",
"{",
"return",
"new",
"FlipResult",
"(",
"\"\"",
",",
"(",
"c",
".",
"Flip",
")",
"res",
")",
";",
"}",
"// dict",
"if",
"(",
"res",
"instanceof",
"c",
".",
"Dict",
")",
"{",
"final",
"c",
".",
"Dict",
"dict",
"=",
"(",
"c",
".",
"Dict",
")",
"res",
";",
"if",
"(",
"(",
"dict",
".",
"x",
"instanceof",
"c",
".",
"Flip",
")",
"&&",
"(",
"dict",
".",
"y",
"instanceof",
"c",
".",
"Flip",
")",
")",
"{",
"final",
"c",
".",
"Flip",
"key",
"=",
"(",
"c",
".",
"Flip",
")",
"dict",
".",
"x",
";",
"final",
"c",
".",
"Flip",
"data",
"=",
"(",
"c",
".",
"Flip",
")",
"dict",
".",
"y",
";",
"return",
"new",
"FlipFlipResult",
"(",
"\"\"",
",",
"key",
",",
"data",
")",
";",
"}",
"}",
"if",
"(",
"res",
"instanceof",
"Object",
"[",
"]",
")",
"{",
"final",
"Object",
"[",
"]",
"oa",
"=",
"(",
"Object",
"[",
"]",
")",
"res",
";",
"if",
"(",
"(",
"oa",
".",
"length",
"==",
"2",
")",
"&&",
"(",
"oa",
"[",
"0",
"]",
"instanceof",
"String",
")",
"&&",
"(",
"oa",
"[",
"1",
"]",
"instanceof",
"c",
".",
"Flip",
")",
")",
"{",
"final",
"String",
"table",
"=",
"(",
"String",
")",
"oa",
"[",
"0",
"]",
";",
"final",
"c",
".",
"Flip",
"flip",
"=",
"(",
"c",
".",
"Flip",
")",
"oa",
"[",
"1",
"]",
";",
"return",
"new",
"FlipResult",
"(",
"table",
",",
"flip",
")",
";",
"}",
"else",
"if",
"(",
"(",
"oa",
".",
"length",
"==",
"3",
")",
"&&",
"(",
"oa",
"[",
"1",
"]",
"instanceof",
"String",
")",
"&&",
"(",
"oa",
"[",
"2",
"]",
"instanceof",
"c",
".",
"Flip",
")",
")",
"{",
"final",
"String",
"table",
"=",
"(",
"String",
")",
"oa",
"[",
"1",
"]",
";",
"final",
"c",
".",
"Flip",
"flip",
"=",
"(",
"c",
".",
"Flip",
")",
"oa",
"[",
"2",
"]",
";",
"return",
"new",
"FlipResult",
"(",
"table",
",",
"flip",
")",
";",
"}",
"else",
"{",
"return",
"new",
"ListResult",
"<",
"Object",
">",
"(",
"oa",
")",
";",
"}",
"}",
"// list",
"if",
"(",
"res",
"instanceof",
"byte",
"[",
"]",
")",
"{",
"return",
"new",
"ListResult",
"<",
"Byte",
">",
"(",
"ArrayUtils",
".",
"toObject",
"(",
"(",
"byte",
"[",
"]",
")",
"res",
")",
")",
";",
"}"
] |
Converts an result from the kx c library to a QConnector Result.
@param res Result from q
@return Result
@throws QConnectorException If the result type is not supported
|
[
"Converts",
"an",
"result",
"from",
"the",
"kx",
"c",
"library",
"to",
"a",
"QConnector",
"Result",
"."
] |
f71fc95b185caa85c6fbdc7179cb4f5f7733b630
|
https://github.com/michaelwittig/java-q/blob/f71fc95b185caa85c6fbdc7179cb4f5f7733b630/src/main/java/info/michaelwittig/javaq/connector/impl/CResultHelper.java#L30-L64
|
10,689
|
threerings/playn
|
core/src/playn/core/AssetWatcher.java
|
AssetWatcher.add
|
public void add(Image image) {
assert !start || listener == null;
++total;
image.addCallback(callback);
}
|
java
|
public void add(Image image) {
assert !start || listener == null;
++total;
image.addCallback(callback);
}
|
[
"public",
"void",
"add",
"(",
"Image",
"image",
")",
"{",
"assert",
"!",
"start",
"||",
"listener",
"==",
"null",
";",
"++",
"total",
";",
"image",
".",
"addCallback",
"(",
"callback",
")",
";",
"}"
] |
Adds an image resource to be watched.
|
[
"Adds",
"an",
"image",
"resource",
"to",
"be",
"watched",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/AssetWatcher.java#L89-L93
|
10,690
|
threerings/playn
|
core/src/playn/core/AssetWatcher.java
|
AssetWatcher.add
|
public void add(Sound sound) {
assert !start || listener == null;
++total;
sound.addCallback(callback);
}
|
java
|
public void add(Sound sound) {
assert !start || listener == null;
++total;
sound.addCallback(callback);
}
|
[
"public",
"void",
"add",
"(",
"Sound",
"sound",
")",
"{",
"assert",
"!",
"start",
"||",
"listener",
"==",
"null",
";",
"++",
"total",
";",
"sound",
".",
"addCallback",
"(",
"callback",
")",
";",
"}"
] |
Adds a sound resource to be watched.
|
[
"Adds",
"a",
"sound",
"resource",
"to",
"be",
"watched",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/AssetWatcher.java#L98-L102
|
10,691
|
threerings/playn
|
core/src/playn/core/gl/GLUtil.java
|
GLUtil.nextPowerOfTwo
|
public static int nextPowerOfTwo(int x) {
assert x < 0x10000;
int bit = 0x8000, highest = -1, count = 0;
for (int i = 15; i >= 0; --i, bit >>= 1) {
if ((x & bit) != 0) {
++count;
if (highest == -1) {
highest = i;
}
}
}
if (count <= 1) {
return 0;
}
return 1 << (highest + 1);
}
|
java
|
public static int nextPowerOfTwo(int x) {
assert x < 0x10000;
int bit = 0x8000, highest = -1, count = 0;
for (int i = 15; i >= 0; --i, bit >>= 1) {
if ((x & bit) != 0) {
++count;
if (highest == -1) {
highest = i;
}
}
}
if (count <= 1) {
return 0;
}
return 1 << (highest + 1);
}
|
[
"public",
"static",
"int",
"nextPowerOfTwo",
"(",
"int",
"x",
")",
"{",
"assert",
"x",
"<",
"0x10000",
";",
"int",
"bit",
"=",
"0x8000",
",",
"highest",
"=",
"-",
"1",
",",
"count",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"15",
";",
"i",
">=",
"0",
";",
"--",
"i",
",",
"bit",
">>=",
"1",
")",
"{",
"if",
"(",
"(",
"x",
"&",
"bit",
")",
"!=",
"0",
")",
"{",
"++",
"count",
";",
"if",
"(",
"highest",
"==",
"-",
"1",
")",
"{",
"highest",
"=",
"i",
";",
"}",
"}",
"}",
"if",
"(",
"count",
"<=",
"1",
")",
"{",
"return",
"0",
";",
"}",
"return",
"1",
"<<",
"(",
"highest",
"+",
"1",
")",
";",
"}"
] |
Returns the next largest power of two, or zero if x is already a power of two.
TODO(jgw): Is there no better way to do this than all this bit twiddling?
|
[
"Returns",
"the",
"next",
"largest",
"power",
"of",
"two",
"or",
"zero",
"if",
"x",
"is",
"already",
"a",
"power",
"of",
"two",
"."
] |
c266eeb39188dcada4b00992a0d1199759e03d42
|
https://github.com/threerings/playn/blob/c266eeb39188dcada4b00992a0d1199759e03d42/core/src/playn/core/gl/GLUtil.java#L22-L38
|
10,692
|
jqm4gwt/jqm4gwt
|
library/src/main/java/com/sksamuel/jqm4gwt/layout/JQMCollapsible.java
|
JQMCollapsible.setInline
|
@Override
public void setInline(boolean value) {
inline = value;
if (headingToggle != null) {
JQMCommon.setInlineEx(headingToggle, value, JQMCommon.STYLE_UI_BTN_INLINE);
}
}
|
java
|
@Override
public void setInline(boolean value) {
inline = value;
if (headingToggle != null) {
JQMCommon.setInlineEx(headingToggle, value, JQMCommon.STYLE_UI_BTN_INLINE);
}
}
|
[
"@",
"Override",
"public",
"void",
"setInline",
"(",
"boolean",
"value",
")",
"{",
"inline",
"=",
"value",
";",
"if",
"(",
"headingToggle",
"!=",
"null",
")",
"{",
"JQMCommon",
".",
"setInlineEx",
"(",
"headingToggle",
",",
"value",
",",
"JQMCommon",
".",
"STYLE_UI_BTN_INLINE",
")",
";",
"}",
"}"
] |
Sets the header button as inline block.
|
[
"Sets",
"the",
"header",
"button",
"as",
"inline",
"block",
"."
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/library/src/main/java/com/sksamuel/jqm4gwt/layout/JQMCollapsible.java#L222-L228
|
10,693
|
jqm4gwt/jqm4gwt
|
library/src/main/java/com/sksamuel/jqm4gwt/layout/JQMCollapsible.java
|
JQMCollapsible.setCollapsed
|
public void setCollapsed(boolean collapsed) {
if (collapsed) {
removeAttribute("data-collapsed");
if (isInstance(getElement())) collapse();
} else {
setAttribute("data-collapsed", "false");
if (isInstance(getElement())) expand();
}
}
|
java
|
public void setCollapsed(boolean collapsed) {
if (collapsed) {
removeAttribute("data-collapsed");
if (isInstance(getElement())) collapse();
} else {
setAttribute("data-collapsed", "false");
if (isInstance(getElement())) expand();
}
}
|
[
"public",
"void",
"setCollapsed",
"(",
"boolean",
"collapsed",
")",
"{",
"if",
"(",
"collapsed",
")",
"{",
"removeAttribute",
"(",
"\"data-collapsed\"",
")",
";",
"if",
"(",
"isInstance",
"(",
"getElement",
"(",
")",
")",
")",
"collapse",
"(",
")",
";",
"}",
"else",
"{",
"setAttribute",
"(",
"\"data-collapsed\"",
",",
"\"false\"",
")",
";",
"if",
"(",
"isInstance",
"(",
"getElement",
"(",
")",
")",
")",
"expand",
"(",
")",
";",
"}",
"}"
] |
Programmatically set the collapsed state of this widget.
|
[
"Programmatically",
"set",
"the",
"collapsed",
"state",
"of",
"this",
"widget",
"."
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/library/src/main/java/com/sksamuel/jqm4gwt/layout/JQMCollapsible.java#L431-L439
|
10,694
|
jqm4gwt/jqm4gwt
|
library/src/main/java/com/sksamuel/jqm4gwt/layout/JQMCollapsible.java
|
JQMCollapsible.setText
|
@Override
public void setText(String text) {
if (headingToggle != null) {
if (text == null) text = "";
String s = headingToggle.getInnerHTML();
int p = s.indexOf('<');
if (p >= 0) s = text + s.substring(p);
else s = text;
headingToggle.setInnerHTML(s);
} else if (!isInstance(getElement())) {
if (headerPanel != null) {
super.remove(headerPanel);
headerPanel = null;
}
header.setText(text);
}
}
|
java
|
@Override
public void setText(String text) {
if (headingToggle != null) {
if (text == null) text = "";
String s = headingToggle.getInnerHTML();
int p = s.indexOf('<');
if (p >= 0) s = text + s.substring(p);
else s = text;
headingToggle.setInnerHTML(s);
} else if (!isInstance(getElement())) {
if (headerPanel != null) {
super.remove(headerPanel);
headerPanel = null;
}
header.setText(text);
}
}
|
[
"@",
"Override",
"public",
"void",
"setText",
"(",
"String",
"text",
")",
"{",
"if",
"(",
"headingToggle",
"!=",
"null",
")",
"{",
"if",
"(",
"text",
"==",
"null",
")",
"text",
"=",
"\"\"",
";",
"String",
"s",
"=",
"headingToggle",
".",
"getInnerHTML",
"(",
")",
";",
"int",
"p",
"=",
"s",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"p",
">=",
"0",
")",
"s",
"=",
"text",
"+",
"s",
".",
"substring",
"(",
"p",
")",
";",
"else",
"s",
"=",
"text",
";",
"headingToggle",
".",
"setInnerHTML",
"(",
"s",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isInstance",
"(",
"getElement",
"(",
")",
")",
")",
"{",
"if",
"(",
"headerPanel",
"!=",
"null",
")",
"{",
"super",
".",
"remove",
"(",
"headerPanel",
")",
";",
"headerPanel",
"=",
"null",
";",
"}",
"header",
".",
"setText",
"(",
"text",
")",
";",
"}",
"}"
] |
Sets the text on the header element
|
[
"Sets",
"the",
"text",
"on",
"the",
"header",
"element"
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/library/src/main/java/com/sksamuel/jqm4gwt/layout/JQMCollapsible.java#L518-L534
|
10,695
|
jqm4gwt/jqm4gwt
|
plugins/datebox/src/main/java/com/sksamuel/jqm4gwt/plugins/datebox/JQMCalBox.java
|
JQMCalBox.formatDate
|
public String formatDate(Date d) {
if (d == null) return null;
JsDate jsd = JsDate.create(d.getTime());
return internFormat(input.getElement(), getActiveDateFormat(), jsd);
}
|
java
|
public String formatDate(Date d) {
if (d == null) return null;
JsDate jsd = JsDate.create(d.getTime());
return internFormat(input.getElement(), getActiveDateFormat(), jsd);
}
|
[
"public",
"String",
"formatDate",
"(",
"Date",
"d",
")",
"{",
"if",
"(",
"d",
"==",
"null",
")",
"return",
"null",
";",
"JsDate",
"jsd",
"=",
"JsDate",
".",
"create",
"(",
"d",
".",
"getTime",
"(",
")",
")",
";",
"return",
"internFormat",
"(",
"input",
".",
"getElement",
"(",
")",
",",
"getActiveDateFormat",
"(",
")",
",",
"jsd",
")",
";",
"}"
] |
Doesn't change anything, just formats passed date as string according to widget's current settings.
|
[
"Doesn",
"t",
"change",
"anything",
"just",
"formats",
"passed",
"date",
"as",
"string",
"according",
"to",
"widget",
"s",
"current",
"settings",
"."
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/plugins/datebox/src/main/java/com/sksamuel/jqm4gwt/plugins/datebox/JQMCalBox.java#L1374-L1378
|
10,696
|
jqm4gwt/jqm4gwt
|
library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java
|
JQMHeader.createButton
|
protected JQMButton createButton(String text, String url, DataIcon icon) {
JQMButton button = new JQMButton(text, url);
if (icon != null)
button.withBuiltInIcon(icon);
return button;
}
|
java
|
protected JQMButton createButton(String text, String url, DataIcon icon) {
JQMButton button = new JQMButton(text, url);
if (icon != null)
button.withBuiltInIcon(icon);
return button;
}
|
[
"protected",
"JQMButton",
"createButton",
"(",
"String",
"text",
",",
"String",
"url",
",",
"DataIcon",
"icon",
")",
"{",
"JQMButton",
"button",
"=",
"new",
"JQMButton",
"(",
"text",
",",
"url",
")",
";",
"if",
"(",
"icon",
"!=",
"null",
")",
"button",
".",
"withBuiltInIcon",
"(",
"icon",
")",
";",
"return",
"button",
";",
"}"
] |
Internal method for creating a button
|
[
"Internal",
"method",
"for",
"creating",
"a",
"button"
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java#L77-L82
|
10,697
|
jqm4gwt/jqm4gwt
|
library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java
|
JQMHeader.setBackButton
|
@UiChild(tagname="backButton", limit=1)
public void setBackButton(JQMButton button) {
button.setBack(true);
setLeftButton(button);
}
|
java
|
@UiChild(tagname="backButton", limit=1)
public void setBackButton(JQMButton button) {
button.setBack(true);
setLeftButton(button);
}
|
[
"@",
"UiChild",
"(",
"tagname",
"=",
"\"backButton\"",
",",
"limit",
"=",
"1",
")",
"public",
"void",
"setBackButton",
"(",
"JQMButton",
"button",
")",
"{",
"button",
".",
"setBack",
"(",
"true",
")",
";",
"setLeftButton",
"(",
"button",
")",
";",
"}"
] |
Sets the given button in the left position and sets that buttons role
to back. Any existing left button will be replaced.
@param button
the new back button
|
[
"Sets",
"the",
"given",
"button",
"in",
"the",
"left",
"position",
"and",
"sets",
"that",
"buttons",
"role",
"to",
"back",
".",
"Any",
"existing",
"left",
"button",
"will",
"be",
"replaced",
"."
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java#L99-L103
|
10,698
|
jqm4gwt/jqm4gwt
|
library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java
|
JQMHeader.setBackButton
|
public JQMButton setBackButton(String text) {
JQMButton button = new JQMButton(text);
button.withBuiltInIcon(DataIcon.LEFT);
setBackButton(button);
return button;
}
|
java
|
public JQMButton setBackButton(String text) {
JQMButton button = new JQMButton(text);
button.withBuiltInIcon(DataIcon.LEFT);
setBackButton(button);
return button;
}
|
[
"public",
"JQMButton",
"setBackButton",
"(",
"String",
"text",
")",
"{",
"JQMButton",
"button",
"=",
"new",
"JQMButton",
"(",
"text",
")",
";",
"button",
".",
"withBuiltInIcon",
"(",
"DataIcon",
".",
"LEFT",
")",
";",
"setBackButton",
"(",
"button",
")",
";",
"return",
"button",
";",
"}"
] |
Creates an auto back button with the given text and replaces the
current left button, if any.
@param text
the the text for the button
@return the created {@link JQMButton}
|
[
"Creates",
"an",
"auto",
"back",
"button",
"with",
"the",
"given",
"text",
"and",
"replaces",
"the",
"current",
"left",
"button",
"if",
"any",
"."
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java#L114-L119
|
10,699
|
jqm4gwt/jqm4gwt
|
library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java
|
JQMHeader.setLeftButton
|
@UiChild(tagname="leftButton", limit=1)
public void setLeftButton(JQMButton button) {
if (left != null) remove(left);
button.setPosOnBand(PosOnBand.LEFT);
left = button;
insert(left, 0);
}
|
java
|
@UiChild(tagname="leftButton", limit=1)
public void setLeftButton(JQMButton button) {
if (left != null) remove(left);
button.setPosOnBand(PosOnBand.LEFT);
left = button;
insert(left, 0);
}
|
[
"@",
"UiChild",
"(",
"tagname",
"=",
"\"leftButton\"",
",",
"limit",
"=",
"1",
")",
"public",
"void",
"setLeftButton",
"(",
"JQMButton",
"button",
")",
"{",
"if",
"(",
"left",
"!=",
"null",
")",
"remove",
"(",
"left",
")",
";",
"button",
".",
"setPosOnBand",
"(",
"PosOnBand",
".",
"LEFT",
")",
";",
"left",
"=",
"button",
";",
"insert",
"(",
"left",
",",
"0",
")",
";",
"}"
] |
Sets the left button to be the given button. Any existing button is removed.
@param button - the button to set on the left slot
|
[
"Sets",
"the",
"left",
"button",
"to",
"be",
"the",
"given",
"button",
".",
"Any",
"existing",
"button",
"is",
"removed",
"."
] |
cf59958e9ba6d4b70f42507b2c77f10c2465085b
|
https://github.com/jqm4gwt/jqm4gwt/blob/cf59958e9ba6d4b70f42507b2c77f10c2465085b/library/src/main/java/com/sksamuel/jqm4gwt/toolbar/JQMHeader.java#L126-L132
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.