repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
casmi/casmi | src/main/java/casmi/matrix/Matrix2D.java | Matrix2D.invert | public boolean invert() {
double determinant = determinant();
if (Math.abs(determinant) <= Double.MIN_VALUE) {
return false;
}
double t00 = m00;
double t01 = m01;
double t02 = m02;
double t10 = m10;
double t11 = m11;
double t12 = m12;
m00 = t11 / determinant;
m10 = -t10 / determinant;
m01 = -t01 / determinant;
m11 = t00 / determinant;
m02 = (t01 * t12 - t11 * t02) / determinant;
m12 = (t10 * t02 - t00 * t12) / determinant;
return true;
} | java | public boolean invert() {
double determinant = determinant();
if (Math.abs(determinant) <= Double.MIN_VALUE) {
return false;
}
double t00 = m00;
double t01 = m01;
double t02 = m02;
double t10 = m10;
double t11 = m11;
double t12 = m12;
m00 = t11 / determinant;
m10 = -t10 / determinant;
m01 = -t01 / determinant;
m11 = t00 / determinant;
m02 = (t01 * t12 - t11 * t02) / determinant;
m12 = (t10 * t02 - t00 * t12) / determinant;
return true;
} | [
"public",
"boolean",
"invert",
"(",
")",
"{",
"double",
"determinant",
"=",
"determinant",
"(",
")",
";",
"if",
"(",
"Math",
".",
"abs",
"(",
"determinant",
")",
"<=",
"Double",
".",
"MIN_VALUE",
")",
"{",
"return",
"false",
";",
"}",
"double",
"t00",
... | Invert this matrix. Implementation stolen from OpenJDK.
@return true if successful | [
"Invert",
"this",
"matrix",
".",
"Implementation",
"stolen",
"from",
"OpenJDK",
"."
] | 90f6514a9cbce0685186e7a92beb69e22a3b11c4 | https://github.com/casmi/casmi/blob/90f6514a9cbce0685186e7a92beb69e22a3b11c4/src/main/java/casmi/matrix/Matrix2D.java#L313-L334 | train |
RestDocArchive/restdoc-api | src/main/java/org/restdoc/api/util/RestDocObject.java | RestDocObject.setAdditionalField | @JsonAnySetter
public void setAdditionalField(final String key, final Object value) {
this.additionalFields.put(key, value);
} | java | @JsonAnySetter
public void setAdditionalField(final String key, final Object value) {
this.additionalFields.put(key, value);
} | [
"@",
"JsonAnySetter",
"public",
"void",
"setAdditionalField",
"(",
"final",
"String",
"key",
",",
"final",
"Object",
"value",
")",
"{",
"this",
".",
"additionalFields",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"}"
] | Add additional field
@param key the field name
@param value the field value | [
"Add",
"additional",
"field"
] | 4bda600d0303229518abf13dbb6ca6a84b4de415 | https://github.com/RestDocArchive/restdoc-api/blob/4bda600d0303229518abf13dbb6ca6a84b4de415/src/main/java/org/restdoc/api/util/RestDocObject.java#L47-L50 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/parser/GenClassFactory.java | GenClassFactory.getGenInstance | public static Object getGenInstance(Class<?> cls, Object... args) throws ParserException
{
Class<?> parserClass = getGenClass(cls);
try
{
if (args.length == 0)
{
return parserClass.newInstance();
}
else
{
for (Constructor constructor : parserClass.getConstructors())
{
Class[] parameterTypes = constructor.getParameterTypes();
if (parameterTypes.length == args.length)
{
boolean match = true;
int index = 0;
for (Class c : parameterTypes)
{
if (!c.isAssignableFrom(args[index++].getClass()))
{
match = false;
break;
}
}
if (match)
{
return constructor.newInstance(args);
}
}
}
throw new IllegalArgumentException("no required constructor for "+cls);
}
}
catch (InstantiationException | IllegalAccessException | SecurityException | IllegalArgumentException | InvocationTargetException ex)
{
throw new ParserException(ex);
}
} | java | public static Object getGenInstance(Class<?> cls, Object... args) throws ParserException
{
Class<?> parserClass = getGenClass(cls);
try
{
if (args.length == 0)
{
return parserClass.newInstance();
}
else
{
for (Constructor constructor : parserClass.getConstructors())
{
Class[] parameterTypes = constructor.getParameterTypes();
if (parameterTypes.length == args.length)
{
boolean match = true;
int index = 0;
for (Class c : parameterTypes)
{
if (!c.isAssignableFrom(args[index++].getClass()))
{
match = false;
break;
}
}
if (match)
{
return constructor.newInstance(args);
}
}
}
throw new IllegalArgumentException("no required constructor for "+cls);
}
}
catch (InstantiationException | IllegalAccessException | SecurityException | IllegalArgumentException | InvocationTargetException ex)
{
throw new ParserException(ex);
}
} | [
"public",
"static",
"Object",
"getGenInstance",
"(",
"Class",
"<",
"?",
">",
"cls",
",",
"Object",
"...",
"args",
")",
"throws",
"ParserException",
"{",
"Class",
"<",
"?",
">",
"parserClass",
"=",
"getGenClass",
"(",
"cls",
")",
";",
"try",
"{",
"if",
... | Creates generated class instance either by using ClassLoader or by compiling it dynamically
@param cls Annotated class acting also as superclass for created parser
@param args
@return
@throws ParserException | [
"Creates",
"generated",
"class",
"instance",
"either",
"by",
"using",
"ClassLoader",
"or",
"by",
"compiling",
"it",
"dynamically"
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/parser/GenClassFactory.java#L44-L84 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/parser/GenClassFactory.java | GenClassFactory.getGenClass | public static Class<?> getGenClass(Class<?> cls) throws ParserException
{
GenClassname genClassname = cls.getAnnotation(GenClassname.class);
if (genClassname == null)
{
throw new IllegalArgumentException("@GenClassname not set in "+cls);
}
try
{
return loadGenClass(cls);
}
catch (ClassNotFoundException ex)
{
throw new ParserException(cls+" classes implementation class not compiled.\n"+
"Possible problem with annotation processor.\n"+
"Try building the whole project and check that implementation class "+genClassname.value()+" exist!");
/*
try
{
GenClassCompiler pc = GenClassCompiler.compile(El.getTypeElement(cls.getCanonicalName()), null);
return pc.loadDynamic();
}
catch (IOException ex1)
{
throw new ParserException(ex1);
}
*/
}
} | java | public static Class<?> getGenClass(Class<?> cls) throws ParserException
{
GenClassname genClassname = cls.getAnnotation(GenClassname.class);
if (genClassname == null)
{
throw new IllegalArgumentException("@GenClassname not set in "+cls);
}
try
{
return loadGenClass(cls);
}
catch (ClassNotFoundException ex)
{
throw new ParserException(cls+" classes implementation class not compiled.\n"+
"Possible problem with annotation processor.\n"+
"Try building the whole project and check that implementation class "+genClassname.value()+" exist!");
/*
try
{
GenClassCompiler pc = GenClassCompiler.compile(El.getTypeElement(cls.getCanonicalName()), null);
return pc.loadDynamic();
}
catch (IOException ex1)
{
throw new ParserException(ex1);
}
*/
}
} | [
"public",
"static",
"Class",
"<",
"?",
">",
"getGenClass",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"throws",
"ParserException",
"{",
"GenClassname",
"genClassname",
"=",
"cls",
".",
"getAnnotation",
"(",
"GenClassname",
".",
"class",
")",
";",
"if",
"(",
... | Creates generated class either by using ClassLoader
@param cls Annotated class acting also as superclass for created parser
@return
@throws ParserException When implementation class is not compiled | [
"Creates",
"generated",
"class",
"either",
"by",
"using",
"ClassLoader"
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/parser/GenClassFactory.java#L91-L119 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/parser/GenClassFactory.java | GenClassFactory.createDynamicInstance | public static Object createDynamicInstance(Class<?> cls) throws IOException
{
GenClassCompiler pc = GenClassCompiler.compile(El.getTypeElement(cls.getCanonicalName()), null);
return pc.loadDynamic();
} | java | public static Object createDynamicInstance(Class<?> cls) throws IOException
{
GenClassCompiler pc = GenClassCompiler.compile(El.getTypeElement(cls.getCanonicalName()), null);
return pc.loadDynamic();
} | [
"public",
"static",
"Object",
"createDynamicInstance",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"throws",
"IOException",
"{",
"GenClassCompiler",
"pc",
"=",
"GenClassCompiler",
".",
"compile",
"(",
"El",
".",
"getTypeElement",
"(",
"cls",
".",
"getCanonicalName"... | Creates instance of implementation class and loads it dynamic. This method
is used in testing.
@param cls
@return
@throws IOException | [
"Creates",
"instance",
"of",
"implementation",
"class",
"and",
"loads",
"it",
"dynamic",
".",
"This",
"method",
"is",
"used",
"in",
"testing",
"."
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/parser/GenClassFactory.java#L127-L131 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/parser/GenClassFactory.java | GenClassFactory.loadGenClass | public static Class<?> loadGenClass(Class<?> cls) throws ClassNotFoundException
{
Class<?> parserClass = map.get(cls);
if (parserClass == null)
{
GenClassname genClassname = cls.getAnnotation(GenClassname.class);
if (genClassname == null)
{
throw new IllegalArgumentException("@GenClassname not set in "+cls);
}
parserClass = Class.forName(genClassname.value());
map.put(cls, parserClass);
}
return parserClass;
} | java | public static Class<?> loadGenClass(Class<?> cls) throws ClassNotFoundException
{
Class<?> parserClass = map.get(cls);
if (parserClass == null)
{
GenClassname genClassname = cls.getAnnotation(GenClassname.class);
if (genClassname == null)
{
throw new IllegalArgumentException("@GenClassname not set in "+cls);
}
parserClass = Class.forName(genClassname.value());
map.put(cls, parserClass);
}
return parserClass;
} | [
"public",
"static",
"Class",
"<",
"?",
">",
"loadGenClass",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"throws",
"ClassNotFoundException",
"{",
"Class",
"<",
"?",
">",
"parserClass",
"=",
"map",
".",
"get",
"(",
"cls",
")",
";",
"if",
"(",
"parserClass",... | Creates generated class by using ClassLoader. Return null if unable to
load class
@param cls Annotated class acting also as superclass for created parser
@return
@throws ClassNotFoundException | [
"Creates",
"generated",
"class",
"by",
"using",
"ClassLoader",
".",
"Return",
"null",
"if",
"unable",
"to",
"load",
"class"
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/parser/GenClassFactory.java#L193-L207 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRImporter.java | LRImporter.getObtainRequestPath | private String getObtainRequestPath(String requestID, Boolean byResourceID, Boolean byDocID, Boolean idsOnly, String resumptionToken)
{
String path = obtainPath;
if (resumptionToken != null)
{
path += "?" + resumptionTokenParam + "=" + resumptionToken;
return path;
}
if (requestID != null)
{
path += "?" + requestIDParam + "=" + requestID;
}
else
{
// error
return null;
}
if (byResourceID)
{
path += "&" + byResourceIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byResourceIDParam + "=" + booleanFalseString;
}
if (byDocID)
{
path += "&" + byDocIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byDocIDParam + "=" + booleanFalseString;
}
if (idsOnly)
{
path += "&" + idsOnlyParam + "=" + booleanTrueString;
}
else
{
path += "&" + idsOnlyParam + "=" + booleanFalseString;
}
return path;
} | java | private String getObtainRequestPath(String requestID, Boolean byResourceID, Boolean byDocID, Boolean idsOnly, String resumptionToken)
{
String path = obtainPath;
if (resumptionToken != null)
{
path += "?" + resumptionTokenParam + "=" + resumptionToken;
return path;
}
if (requestID != null)
{
path += "?" + requestIDParam + "=" + requestID;
}
else
{
// error
return null;
}
if (byResourceID)
{
path += "&" + byResourceIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byResourceIDParam + "=" + booleanFalseString;
}
if (byDocID)
{
path += "&" + byDocIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byDocIDParam + "=" + booleanFalseString;
}
if (idsOnly)
{
path += "&" + idsOnlyParam + "=" + booleanTrueString;
}
else
{
path += "&" + idsOnlyParam + "=" + booleanFalseString;
}
return path;
} | [
"private",
"String",
"getObtainRequestPath",
"(",
"String",
"requestID",
",",
"Boolean",
"byResourceID",
",",
"Boolean",
"byDocID",
",",
"Boolean",
"idsOnly",
",",
"String",
"resumptionToken",
")",
"{",
"String",
"path",
"=",
"obtainPath",
";",
"if",
"(",
"resum... | Obtain the path used for an obtain request
@param requestID the "request_ID" parameter for the request
@param byResourceID the "by_resource_ID" parameter for the request
@param byDocID the "by_doc_ID" parameter for the request
@param idsOnly the "ids_only" parameter for the request
@param resumptionToken the "resumption_token" parameter for the request
@return the string of the path for an obtain request | [
"Obtain",
"the",
"path",
"used",
"for",
"an",
"obtain",
"request"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRImporter.java#L118-L166 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRImporter.java | LRImporter.getHarvestRequestPath | private String getHarvestRequestPath(String requestID, Boolean byResourceID, Boolean byDocID)
{
String path = harvestPath;
if (requestID != null)
{
path += "?" + requestIDParam + "=" + requestID;
}
else
{
// error
return null;
}
if (byResourceID)
{
path += "&" + byResourceIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byResourceIDParam + "=" + booleanFalseString;
}
if (byDocID)
{
path += "&" + byDocIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byDocIDParam + "=" + booleanFalseString;
}
return path;
} | java | private String getHarvestRequestPath(String requestID, Boolean byResourceID, Boolean byDocID)
{
String path = harvestPath;
if (requestID != null)
{
path += "?" + requestIDParam + "=" + requestID;
}
else
{
// error
return null;
}
if (byResourceID)
{
path += "&" + byResourceIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byResourceIDParam + "=" + booleanFalseString;
}
if (byDocID)
{
path += "&" + byDocIDParam + "=" + booleanTrueString;
}
else
{
path += "&" + byDocIDParam + "=" + booleanFalseString;
}
return path;
} | [
"private",
"String",
"getHarvestRequestPath",
"(",
"String",
"requestID",
",",
"Boolean",
"byResourceID",
",",
"Boolean",
"byDocID",
")",
"{",
"String",
"path",
"=",
"harvestPath",
";",
"if",
"(",
"requestID",
"!=",
"null",
")",
"{",
"path",
"+=",
"\"?\"",
"... | Obtain the path used for a harvest request
@param requestID the "request_ID" parameter for the request
@param byResourceID the "by_resource_ID" parameter for the request
@param byDocID the "by_doc_ID" parameter for the request
@return the string of the path for a harvest request | [
"Obtain",
"the",
"path",
"used",
"for",
"a",
"harvest",
"request"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRImporter.java#L176-L209 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRImporter.java | LRImporter.getObtainJSONData | private LRResult getObtainJSONData(String requestID, Boolean byResourceID, Boolean byDocID, Boolean idsOnly, String resumptionToken) throws LRException
{
String path = getObtainRequestPath(requestID, byResourceID, byDocID, idsOnly, resumptionToken);
JSONObject json = getJSONFromPath(path);
return new LRResult(json);
} | java | private LRResult getObtainJSONData(String requestID, Boolean byResourceID, Boolean byDocID, Boolean idsOnly, String resumptionToken) throws LRException
{
String path = getObtainRequestPath(requestID, byResourceID, byDocID, idsOnly, resumptionToken);
JSONObject json = getJSONFromPath(path);
return new LRResult(json);
} | [
"private",
"LRResult",
"getObtainJSONData",
"(",
"String",
"requestID",
",",
"Boolean",
"byResourceID",
",",
"Boolean",
"byDocID",
",",
"Boolean",
"idsOnly",
",",
"String",
"resumptionToken",
")",
"throws",
"LRException",
"{",
"String",
"path",
"=",
"getObtainReques... | Get a result from an obtain request
If the resumption token is not null, it will override the other parameters for ths request
@param requestID the "request_id" value to use for this request
@param byResourceID the "by_resource_id" value to use for this request
@param byDocID the "by_doc_id" value to use for this request
@param idsOnly the "ids_only" value to use for this request
@param resumptionToken the "resumption_token" value to use for this request
@return the result from this request | [
"Get",
"a",
"result",
"from",
"an",
"obtain",
"request",
"If",
"the",
"resumption",
"token",
"is",
"not",
"null",
"it",
"will",
"override",
"the",
"other",
"parameters",
"for",
"ths",
"request"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRImporter.java#L247-L254 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRImporter.java | LRImporter.getHarvestJSONData | public LRResult getHarvestJSONData(String requestID, Boolean byResourceID, Boolean byDocID) throws LRException
{
String path = getHarvestRequestPath(requestID, byResourceID, byDocID);
JSONObject json = getJSONFromPath(path);
return new LRResult(json);
} | java | public LRResult getHarvestJSONData(String requestID, Boolean byResourceID, Boolean byDocID) throws LRException
{
String path = getHarvestRequestPath(requestID, byResourceID, byDocID);
JSONObject json = getJSONFromPath(path);
return new LRResult(json);
} | [
"public",
"LRResult",
"getHarvestJSONData",
"(",
"String",
"requestID",
",",
"Boolean",
"byResourceID",
",",
"Boolean",
"byDocID",
")",
"throws",
"LRException",
"{",
"String",
"path",
"=",
"getHarvestRequestPath",
"(",
"requestID",
",",
"byResourceID",
",",
"byDocID... | Get a result from a harvest request
@param requestID the "request_id" value to use for this request
@param byResourceID the "by_resource_id" value to use for this request
@param byDocID the "by_doc_id" value to use for this request
@return the result from this request | [
"Get",
"a",
"result",
"from",
"a",
"harvest",
"request"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRImporter.java#L264-L271 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRImporter.java | LRImporter.getExtractRequestPath | private String getExtractRequestPath(String dataServiceName, String viewName, Date from, Date until, Boolean idsOnly, String mainValue, Boolean partial, String mainName)
{
String path = extractPath;
if (viewName != null)
{
path += "/" + viewName;
}
else
{
return null;
}
if (dataServiceName != null)
{
path += "/" + dataServiceName;
}
else
{
return null;
}
if (mainValue != null && mainName != null)
{
path += "?" + mainName;
if (partial)
{
path += startsWithParam;
}
path += "=" + mainValue;
}
else
{
return null;
}
if (from != null)
{
path += "&" + fromParam + "=" + ISO8601.format(from);
}
if (until != null)
{
path += "&" + untilParam + "=" + ISO8601.format(until);
}
if (idsOnly)
{
path += "&" + idsOnlyParam + "=" + booleanTrueString;
}
return path;
} | java | private String getExtractRequestPath(String dataServiceName, String viewName, Date from, Date until, Boolean idsOnly, String mainValue, Boolean partial, String mainName)
{
String path = extractPath;
if (viewName != null)
{
path += "/" + viewName;
}
else
{
return null;
}
if (dataServiceName != null)
{
path += "/" + dataServiceName;
}
else
{
return null;
}
if (mainValue != null && mainName != null)
{
path += "?" + mainName;
if (partial)
{
path += startsWithParam;
}
path += "=" + mainValue;
}
else
{
return null;
}
if (from != null)
{
path += "&" + fromParam + "=" + ISO8601.format(from);
}
if (until != null)
{
path += "&" + untilParam + "=" + ISO8601.format(until);
}
if (idsOnly)
{
path += "&" + idsOnlyParam + "=" + booleanTrueString;
}
return path;
} | [
"private",
"String",
"getExtractRequestPath",
"(",
"String",
"dataServiceName",
",",
"String",
"viewName",
",",
"Date",
"from",
",",
"Date",
"until",
",",
"Boolean",
"idsOnly",
",",
"String",
"mainValue",
",",
"Boolean",
"partial",
",",
"String",
"mainName",
")"... | Get an extract request path
@param dataServiceName name of the data service to use
@param viewName name of the view to use
@param from start date from which to extract items
@param until end date from which to extract items
@param idsOnly true/false to only extract ids
@param mainValue value of the main field
@param partial true/false is the main field is a partial value
@param mainName name of the main field (e.g. resource, discriminator)
@return the extract request path with the given parameters | [
"Get",
"an",
"extract",
"request",
"path"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRImporter.java#L286-L340 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRImporter.java | LRImporter.getJSONFromPath | private JSONObject getJSONFromPath(String path) throws LRException
{
JSONObject json = null;
String jsonTxt = null;
try
{
jsonTxt = LRClient.executeJsonGet(importProtocol + "://" + nodeHost + path);
}
catch(Exception e)
{
throw new LRException(LRException.IMPORT_FAILED);
//e.printStackTrace();
}
try
{
json = new JSONObject(jsonTxt);
}
catch(JSONException e)
{
throw new LRException(LRException.JSON_IMPORT_FAILED);
//e.printStackTrace();
}
return json;
} | java | private JSONObject getJSONFromPath(String path) throws LRException
{
JSONObject json = null;
String jsonTxt = null;
try
{
jsonTxt = LRClient.executeJsonGet(importProtocol + "://" + nodeHost + path);
}
catch(Exception e)
{
throw new LRException(LRException.IMPORT_FAILED);
//e.printStackTrace();
}
try
{
json = new JSONObject(jsonTxt);
}
catch(JSONException e)
{
throw new LRException(LRException.JSON_IMPORT_FAILED);
//e.printStackTrace();
}
return json;
} | [
"private",
"JSONObject",
"getJSONFromPath",
"(",
"String",
"path",
")",
"throws",
"LRException",
"{",
"JSONObject",
"json",
"=",
"null",
";",
"String",
"jsonTxt",
"=",
"null",
";",
"try",
"{",
"jsonTxt",
"=",
"LRClient",
".",
"executeJsonGet",
"(",
"importProt... | Get the data from the specified path as a JSONObject
@param path the path to use for this request
@return the JSON from the request | [
"Get",
"the",
"data",
"from",
"the",
"specified",
"path",
"as",
"a",
"JSONObject"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRImporter.java#L430-L456 | train |
casmi/casmi | src/main/java/casmi/graphics/font/Font.java | Font.fontStyleToInt | private static int fontStyleToInt(FontStyle style) {
switch (style) {
case PLAIN:
return java.awt.Font.PLAIN;
case BOLD:
return java.awt.Font.BOLD;
case ITALIC:
return java.awt.Font.ITALIC;
default:
return java.awt.Font.PLAIN;
}
} | java | private static int fontStyleToInt(FontStyle style) {
switch (style) {
case PLAIN:
return java.awt.Font.PLAIN;
case BOLD:
return java.awt.Font.BOLD;
case ITALIC:
return java.awt.Font.ITALIC;
default:
return java.awt.Font.PLAIN;
}
} | [
"private",
"static",
"int",
"fontStyleToInt",
"(",
"FontStyle",
"style",
")",
"{",
"switch",
"(",
"style",
")",
"{",
"case",
"PLAIN",
":",
"return",
"java",
".",
"awt",
".",
"Font",
".",
"PLAIN",
";",
"case",
"BOLD",
":",
"return",
"java",
".",
"awt",
... | Return a java.awt.Font style constant from FontStyle.
@param style
FontStyle value.
@return A java.awt.Font style constant. | [
"Return",
"a",
"java",
".",
"awt",
".",
"Font",
"style",
"constant",
"from",
"FontStyle",
"."
] | 90f6514a9cbce0685186e7a92beb69e22a3b11c4 | https://github.com/casmi/casmi/blob/90f6514a9cbce0685186e7a92beb69e22a3b11c4/src/main/java/casmi/graphics/font/Font.java#L294-L305 | train |
casmi/casmi | src/main/java/casmi/graphics/font/Font.java | Font.intToFontStyle | private static FontStyle intToFontStyle(int style) {
switch (style) {
case java.awt.Font.PLAIN:
return FontStyle.PLAIN;
case java.awt.Font.BOLD:
return FontStyle.BOLD;
case java.awt.Font.ITALIC:
return FontStyle.ITALIC;
case java.awt.Font.BOLD + java.awt.Font.ITALIC:
return FontStyle.BOLD_ITALIC;
default:
return FontStyle.PLAIN;
}
} | java | private static FontStyle intToFontStyle(int style) {
switch (style) {
case java.awt.Font.PLAIN:
return FontStyle.PLAIN;
case java.awt.Font.BOLD:
return FontStyle.BOLD;
case java.awt.Font.ITALIC:
return FontStyle.ITALIC;
case java.awt.Font.BOLD + java.awt.Font.ITALIC:
return FontStyle.BOLD_ITALIC;
default:
return FontStyle.PLAIN;
}
} | [
"private",
"static",
"FontStyle",
"intToFontStyle",
"(",
"int",
"style",
")",
"{",
"switch",
"(",
"style",
")",
"{",
"case",
"java",
".",
"awt",
".",
"Font",
".",
"PLAIN",
":",
"return",
"FontStyle",
".",
"PLAIN",
";",
"case",
"java",
".",
"awt",
".",
... | Return FontStyle enum value from java.awt.Font style constant.
@param style
java.awt.Font style constant value.
@return FontStyle value. | [
"Return",
"FontStyle",
"enum",
"value",
"from",
"java",
".",
"awt",
".",
"Font",
"style",
"constant",
"."
] | 90f6514a9cbce0685186e7a92beb69e22a3b11c4 | https://github.com/casmi/casmi/blob/90f6514a9cbce0685186e7a92beb69e22a3b11c4/src/main/java/casmi/graphics/font/Font.java#L314-L327 | train |
casmi/casmi | src/main/java/casmi/graphics/font/Font.java | Font.stringToFontStyle | private static FontStyle stringToFontStyle(String style) {
if (style.compareToIgnoreCase("plain") == 0) {
return FontStyle.PLAIN;
} else if (style.compareToIgnoreCase("bold") == 0) {
return FontStyle.BOLD;
} else if (style.compareToIgnoreCase("italic") == 0) {
return FontStyle.ITALIC;
} else {
throw new IllegalArgumentException();
}
} | java | private static FontStyle stringToFontStyle(String style) {
if (style.compareToIgnoreCase("plain") == 0) {
return FontStyle.PLAIN;
} else if (style.compareToIgnoreCase("bold") == 0) {
return FontStyle.BOLD;
} else if (style.compareToIgnoreCase("italic") == 0) {
return FontStyle.ITALIC;
} else {
throw new IllegalArgumentException();
}
} | [
"private",
"static",
"FontStyle",
"stringToFontStyle",
"(",
"String",
"style",
")",
"{",
"if",
"(",
"style",
".",
"compareToIgnoreCase",
"(",
"\"plain\"",
")",
"==",
"0",
")",
"{",
"return",
"FontStyle",
".",
"PLAIN",
";",
"}",
"else",
"if",
"(",
"style",
... | Return FontStyle enum value from a font style name.
@param style
A style name like "italic".
@return FontStyle enum value. | [
"Return",
"FontStyle",
"enum",
"value",
"from",
"a",
"font",
"style",
"name",
"."
] | 90f6514a9cbce0685186e7a92beb69e22a3b11c4 | https://github.com/casmi/casmi/blob/90f6514a9cbce0685186e7a92beb69e22a3b11c4/src/main/java/casmi/graphics/font/Font.java#L336-L346 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/rest/EFapsResourceConfig.java | EFapsResourceConfig.onReload | public void onReload(final Container _container)
{
final Set<Class<?>> classesToRemove = new HashSet<>();
final Set<Class<?>> classesToAdd = new HashSet<>();
for (final Class<?> c : getClasses()) {
if (!this.cachedClasses.contains(c)) {
classesToAdd.add(c);
}
}
for (final Class<?> c : this.cachedClasses) {
if (!getClasses().contains(c)) {
classesToRemove.add(c);
}
}
getClasses().clear();
init();
getClasses().addAll(classesToAdd);
getClasses().removeAll(classesToRemove);
} | java | public void onReload(final Container _container)
{
final Set<Class<?>> classesToRemove = new HashSet<>();
final Set<Class<?>> classesToAdd = new HashSet<>();
for (final Class<?> c : getClasses()) {
if (!this.cachedClasses.contains(c)) {
classesToAdd.add(c);
}
}
for (final Class<?> c : this.cachedClasses) {
if (!getClasses().contains(c)) {
classesToRemove.add(c);
}
}
getClasses().clear();
init();
getClasses().addAll(classesToAdd);
getClasses().removeAll(classesToRemove);
} | [
"public",
"void",
"onReload",
"(",
"final",
"Container",
"_container",
")",
"{",
"final",
"Set",
"<",
"Class",
"<",
"?",
">",
">",
"classesToRemove",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"final",
"Set",
"<",
"Class",
"<",
"?",
">",
">",
"class... | Perform a new search for resource classes and provider classes.
@param _container Container | [
"Perform",
"a",
"new",
"search",
"for",
"resource",
"classes",
"and",
"provider",
"classes",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/rest/EFapsResourceConfig.java#L139-L162 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/stmt/selection/Selection.java | Selection.addInstSelect | private void addInstSelect(final Select _select, final AbstractDataElement<?> _element, final Object _attrOrClass,
final Type _currentType)
throws CacheReloadException
{
if (StringUtils.isNotEmpty(_element.getPath()) && !this.instSelects.containsKey(_element.getPath())) {
final Select instSelect = Select.get();
for (final AbstractElement<?> selectTmp : _select.getElements()) {
if (!selectTmp.equals(_element)) {
if (selectTmp instanceof LinktoElement) {
instSelect.addElement(new LinktoElement().setAttribute(((LinktoElement) selectTmp)
.getAttribute()));
} else if (selectTmp instanceof LinkfromElement) {
instSelect.addElement(new LinkfromElement().setAttribute(((LinkfromElement) selectTmp)
.getAttribute()).setStartType(((LinkfromElement) selectTmp).getStartType()));
} else if (selectTmp instanceof ClassElement) {
instSelect.addElement(new ClassElement()
.setClassification(((ClassElement) selectTmp).getClassification())
.setType(((ClassElement) selectTmp).getType()));
} else if (selectTmp instanceof AttributeSetElement) {
instSelect.addElement(new AttributeSetElement()
.setAttributeSet(((AttributeSetElement) selectTmp).getAttributeSet())
.setType(((ClassElement) selectTmp).getType()));
}
}
}
if (_element instanceof LinkfromElement) {
instSelect.addElement(new LinkfromElement().setAttribute((Attribute) _attrOrClass).setStartType(
_currentType));
instSelect.addElement(new InstanceElement(((Attribute) _attrOrClass).getParent()));
} else if (_element instanceof LinktoElement) {
instSelect.addElement(new LinktoElement().setAttribute((Attribute) _attrOrClass));
instSelect.addElement(new InstanceElement(_currentType));
} else if (_element instanceof ClassElement) {
instSelect.addElement(new ClassElement().setClassification((Classification) _attrOrClass)
.setType(_currentType));
instSelect.addElement(new InstanceElement((Type) _attrOrClass));
} else if (_element instanceof AttributeSetElement) {
instSelect.addElement(new AttributeSetElement().setAttributeSet((AttributeSet) _attrOrClass)
.setType(_currentType));
instSelect.addElement(new InstanceElement((Type) _attrOrClass));
}
this.instSelects.put(_element.getPath(), instSelect);
}
} | java | private void addInstSelect(final Select _select, final AbstractDataElement<?> _element, final Object _attrOrClass,
final Type _currentType)
throws CacheReloadException
{
if (StringUtils.isNotEmpty(_element.getPath()) && !this.instSelects.containsKey(_element.getPath())) {
final Select instSelect = Select.get();
for (final AbstractElement<?> selectTmp : _select.getElements()) {
if (!selectTmp.equals(_element)) {
if (selectTmp instanceof LinktoElement) {
instSelect.addElement(new LinktoElement().setAttribute(((LinktoElement) selectTmp)
.getAttribute()));
} else if (selectTmp instanceof LinkfromElement) {
instSelect.addElement(new LinkfromElement().setAttribute(((LinkfromElement) selectTmp)
.getAttribute()).setStartType(((LinkfromElement) selectTmp).getStartType()));
} else if (selectTmp instanceof ClassElement) {
instSelect.addElement(new ClassElement()
.setClassification(((ClassElement) selectTmp).getClassification())
.setType(((ClassElement) selectTmp).getType()));
} else if (selectTmp instanceof AttributeSetElement) {
instSelect.addElement(new AttributeSetElement()
.setAttributeSet(((AttributeSetElement) selectTmp).getAttributeSet())
.setType(((ClassElement) selectTmp).getType()));
}
}
}
if (_element instanceof LinkfromElement) {
instSelect.addElement(new LinkfromElement().setAttribute((Attribute) _attrOrClass).setStartType(
_currentType));
instSelect.addElement(new InstanceElement(((Attribute) _attrOrClass).getParent()));
} else if (_element instanceof LinktoElement) {
instSelect.addElement(new LinktoElement().setAttribute((Attribute) _attrOrClass));
instSelect.addElement(new InstanceElement(_currentType));
} else if (_element instanceof ClassElement) {
instSelect.addElement(new ClassElement().setClassification((Classification) _attrOrClass)
.setType(_currentType));
instSelect.addElement(new InstanceElement((Type) _attrOrClass));
} else if (_element instanceof AttributeSetElement) {
instSelect.addElement(new AttributeSetElement().setAttributeSet((AttributeSet) _attrOrClass)
.setType(_currentType));
instSelect.addElement(new InstanceElement((Type) _attrOrClass));
}
this.instSelects.put(_element.getPath(), instSelect);
}
} | [
"private",
"void",
"addInstSelect",
"(",
"final",
"Select",
"_select",
",",
"final",
"AbstractDataElement",
"<",
"?",
">",
"_element",
",",
"final",
"Object",
"_attrOrClass",
",",
"final",
"Type",
"_currentType",
")",
"throws",
"CacheReloadException",
"{",
"if",
... | Adds the inst select.
@param _select the select
@param _element the element
@param _attr the attr
@param _currentType the current type
@throws CacheReloadException on error | [
"Adds",
"the",
"inst",
"select",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/stmt/selection/Selection.java#L211-L254 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/stmt/selection/Selection.java | Selection.evalMainType | private Type evalMainType(final Collection<Type> _baseTypes)
throws EFapsException
{
final Type ret;
if (_baseTypes.size() == 1) {
ret = _baseTypes.iterator().next();
} else {
final List<List<Type>> typeLists = new ArrayList<>();
for (final Type type : _baseTypes) {
final List<Type> typesTmp = new ArrayList<>();
typeLists.add(typesTmp);
Type tmpType = type;
while (tmpType != null) {
typesTmp.add(tmpType);
tmpType = tmpType.getParentType();
}
}
final Set<Type> common = new LinkedHashSet<>();
if (!typeLists.isEmpty()) {
final Iterator<List<Type>> iterator = typeLists.iterator();
common.addAll(iterator.next());
while (iterator.hasNext()) {
common.retainAll(iterator.next());
}
}
if (common.isEmpty()) {
throw new EFapsException(Selection.class, "noCommon", _baseTypes);
} else {
// first common type
ret = common.iterator().next();
}
}
return ret;
} | java | private Type evalMainType(final Collection<Type> _baseTypes)
throws EFapsException
{
final Type ret;
if (_baseTypes.size() == 1) {
ret = _baseTypes.iterator().next();
} else {
final List<List<Type>> typeLists = new ArrayList<>();
for (final Type type : _baseTypes) {
final List<Type> typesTmp = new ArrayList<>();
typeLists.add(typesTmp);
Type tmpType = type;
while (tmpType != null) {
typesTmp.add(tmpType);
tmpType = tmpType.getParentType();
}
}
final Set<Type> common = new LinkedHashSet<>();
if (!typeLists.isEmpty()) {
final Iterator<List<Type>> iterator = typeLists.iterator();
common.addAll(iterator.next());
while (iterator.hasNext()) {
common.retainAll(iterator.next());
}
}
if (common.isEmpty()) {
throw new EFapsException(Selection.class, "noCommon", _baseTypes);
} else {
// first common type
ret = common.iterator().next();
}
}
return ret;
} | [
"private",
"Type",
"evalMainType",
"(",
"final",
"Collection",
"<",
"Type",
">",
"_baseTypes",
")",
"throws",
"EFapsException",
"{",
"final",
"Type",
"ret",
";",
"if",
"(",
"_baseTypes",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"ret",
"=",
"_baseTypes... | Gets the main type.
@param _baseTypes the base types
@return the main type
@throws EFapsException on error | [
"Gets",
"the",
"main",
"type",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/stmt/selection/Selection.java#L263-L297 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/stmt/selection/Selection.java | Selection.getAllSelects | public Collection<Select> getAllSelects()
{
final List<Select> ret = new ArrayList<>(this.selects);
ret.addAll(this.instSelects.values());
return Collections.unmodifiableCollection(ret);
} | java | public Collection<Select> getAllSelects()
{
final List<Select> ret = new ArrayList<>(this.selects);
ret.addAll(this.instSelects.values());
return Collections.unmodifiableCollection(ret);
} | [
"public",
"Collection",
"<",
"Select",
">",
"getAllSelects",
"(",
")",
"{",
"final",
"List",
"<",
"Select",
">",
"ret",
"=",
"new",
"ArrayList",
"<>",
"(",
"this",
".",
"selects",
")",
";",
"ret",
".",
"addAll",
"(",
"this",
".",
"instSelects",
".",
... | Gets the all data selects.
@return the all selects | [
"Gets",
"the",
"all",
"data",
"selects",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/stmt/selection/Selection.java#L324-L329 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/admin/user/AbstractUserObject.java | AbstractUserObject.unassignFromUserObjectInDb | protected void unassignFromUserObjectInDb(final Type _unassignType,
final JAASSystem _jaasSystem,
final AbstractUserObject _object)
throws EFapsException
{
Connection con = null;
try {
con = Context.getConnection();
Statement stmt = null;
final StringBuilder cmd = new StringBuilder();
try {
cmd.append("delete from ").append(_unassignType.getMainTable().getSqlTable()).append(" ").append(
"where USERJAASSYSTEM=").append(_jaasSystem.getId()).append(" ").append(
"and USERABSTRACTFROM=").append(getId()).append(" ").append("and USERABSTRACTTO=")
.append(_object.getId());
stmt = con.createStatement();
stmt.executeUpdate(cmd.toString());
} catch (final SQLException e) {
AbstractUserObject.LOG.error("could not execute '" + cmd.toString()
+ "' to unassign user object '" + toString()
+ "' from object '" + _object + "' for JAAS system '" + _jaasSystem + "' ", e);
throw new EFapsException(getClass(), "unassignFromUserObjectInDb.SQLException", e, cmd.toString(),
getName());
} finally {
try {
if (stmt != null) {
stmt.close();
}
con.commit();
} catch (final SQLException e) {
AbstractUserObject.LOG.error("Could not close a statement.", e);
}
}
} finally {
try {
if (con != null && !con.isClosed()) {
con.close();
}
} catch (final SQLException e) {
throw new CacheReloadException("Cannot read a type for an attribute.", e);
}
}
} | java | protected void unassignFromUserObjectInDb(final Type _unassignType,
final JAASSystem _jaasSystem,
final AbstractUserObject _object)
throws EFapsException
{
Connection con = null;
try {
con = Context.getConnection();
Statement stmt = null;
final StringBuilder cmd = new StringBuilder();
try {
cmd.append("delete from ").append(_unassignType.getMainTable().getSqlTable()).append(" ").append(
"where USERJAASSYSTEM=").append(_jaasSystem.getId()).append(" ").append(
"and USERABSTRACTFROM=").append(getId()).append(" ").append("and USERABSTRACTTO=")
.append(_object.getId());
stmt = con.createStatement();
stmt.executeUpdate(cmd.toString());
} catch (final SQLException e) {
AbstractUserObject.LOG.error("could not execute '" + cmd.toString()
+ "' to unassign user object '" + toString()
+ "' from object '" + _object + "' for JAAS system '" + _jaasSystem + "' ", e);
throw new EFapsException(getClass(), "unassignFromUserObjectInDb.SQLException", e, cmd.toString(),
getName());
} finally {
try {
if (stmt != null) {
stmt.close();
}
con.commit();
} catch (final SQLException e) {
AbstractUserObject.LOG.error("Could not close a statement.", e);
}
}
} finally {
try {
if (con != null && !con.isClosed()) {
con.close();
}
} catch (final SQLException e) {
throw new CacheReloadException("Cannot read a type for an attribute.", e);
}
}
} | [
"protected",
"void",
"unassignFromUserObjectInDb",
"(",
"final",
"Type",
"_unassignType",
",",
"final",
"JAASSystem",
"_jaasSystem",
",",
"final",
"AbstractUserObject",
"_object",
")",
"throws",
"EFapsException",
"{",
"Connection",
"con",
"=",
"null",
";",
"try",
"{... | Unassign this user object from the given user object for given JAAS
system.
@param _unassignType type used to unassign (in other words the
relationship type)
@param _jaasSystem JAAS system for which this user object is unassigned
from given object
@param _object user object from which this user object is unassigned
@throws EFapsException if unassignment could not be done | [
"Unassign",
"this",
"user",
"object",
"from",
"the",
"given",
"user",
"object",
"for",
"given",
"JAAS",
"system",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/admin/user/AbstractUserObject.java#L280-L324 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/admin/user/AbstractUserObject.java | AbstractUserObject.setStatusInDB | protected void setStatusInDB(final boolean _status)
throws EFapsException
{
Connection con = null;
try {
con = Context.getConnection();
PreparedStatement stmt = null;
final StringBuilder cmd = new StringBuilder();
try {
cmd.append(" update T_USERABSTRACT set STATUS=? where ID=").append(getId());
stmt = con.prepareStatement(cmd.toString());
stmt.setBoolean(1, _status);
final int rows = stmt.executeUpdate();
if (rows == 0) {
AbstractUserObject.LOG.error("could not execute '" + cmd.toString()
+ "' to update status information for person '" + toString() + "'");
throw new EFapsException(getClass(), "setStatusInDB.NotUpdated", cmd.toString(), getName());
}
} catch (final SQLException e) {
AbstractUserObject.LOG.error("could not execute '" + cmd.toString()
+ "' to update status information for person '" + toString() + "'", e);
throw new EFapsException(getClass(), "setStatusInDB.SQLException", e, cmd.toString(), getName());
} finally {
try {
if (stmt != null) {
stmt.close();
}
con.commit();
} catch (final SQLException e) {
throw new EFapsException(getClass(), "setStatusInDB.SQLException", e, cmd.toString(), getName());
}
}
} finally {
try {
if (con != null && !con.isClosed()) {
con.close();
}
} catch (final SQLException e) {
throw new CacheReloadException("Cannot read a type for an attribute.", e);
}
}
} | java | protected void setStatusInDB(final boolean _status)
throws EFapsException
{
Connection con = null;
try {
con = Context.getConnection();
PreparedStatement stmt = null;
final StringBuilder cmd = new StringBuilder();
try {
cmd.append(" update T_USERABSTRACT set STATUS=? where ID=").append(getId());
stmt = con.prepareStatement(cmd.toString());
stmt.setBoolean(1, _status);
final int rows = stmt.executeUpdate();
if (rows == 0) {
AbstractUserObject.LOG.error("could not execute '" + cmd.toString()
+ "' to update status information for person '" + toString() + "'");
throw new EFapsException(getClass(), "setStatusInDB.NotUpdated", cmd.toString(), getName());
}
} catch (final SQLException e) {
AbstractUserObject.LOG.error("could not execute '" + cmd.toString()
+ "' to update status information for person '" + toString() + "'", e);
throw new EFapsException(getClass(), "setStatusInDB.SQLException", e, cmd.toString(), getName());
} finally {
try {
if (stmt != null) {
stmt.close();
}
con.commit();
} catch (final SQLException e) {
throw new EFapsException(getClass(), "setStatusInDB.SQLException", e, cmd.toString(), getName());
}
}
} finally {
try {
if (con != null && !con.isClosed()) {
con.close();
}
} catch (final SQLException e) {
throw new CacheReloadException("Cannot read a type for an attribute.", e);
}
}
} | [
"protected",
"void",
"setStatusInDB",
"(",
"final",
"boolean",
"_status",
")",
"throws",
"EFapsException",
"{",
"Connection",
"con",
"=",
"null",
";",
"try",
"{",
"con",
"=",
"Context",
".",
"getConnection",
"(",
")",
";",
"PreparedStatement",
"stmt",
"=",
"... | Method to set the status of a UserObject in the eFaps Database.
@param _status status to set
@throws EFapsException on error | [
"Method",
"to",
"set",
"the",
"status",
"of",
"a",
"UserObject",
"in",
"the",
"eFaps",
"Database",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/admin/user/AbstractUserObject.java#L382-L424 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/admin/ui/AbstractUserInterfaceObject.java | AbstractUserInterfaceObject.readFromDB4Access | private void readFromDB4Access()
throws CacheReloadException
{
Statement stmt = null;
try {
stmt = Context.getThreadContext().getConnectionResource().createStatement();
final ResultSet resultset = stmt.executeQuery("select "
+ "T_UIACCESS.USERABSTRACT "
+ "from T_UIACCESS "
+ "where T_UIACCESS.UIABSTRACT=" + getId());
while (resultset.next()) {
final long userId = resultset.getLong(1);
final AbstractUserObject userObject = AbstractUserObject.getUserObject(userId);
if (userObject == null) {
throw new CacheReloadException("user " + userId + " does not exists!");
} else {
getAccess().add(userId);
}
}
resultset.close();
} catch (final SQLException e) {
throw new CacheReloadException("could not read access for " + "'" + getName() + "'", e);
} catch (final EFapsException e) {
throw new CacheReloadException("could not read access for " + "'" + getName() + "'", e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (final SQLException e) {
throw new CacheReloadException("could not read access for " + "'" + getName() + "'", e);
}
}
}
} | java | private void readFromDB4Access()
throws CacheReloadException
{
Statement stmt = null;
try {
stmt = Context.getThreadContext().getConnectionResource().createStatement();
final ResultSet resultset = stmt.executeQuery("select "
+ "T_UIACCESS.USERABSTRACT "
+ "from T_UIACCESS "
+ "where T_UIACCESS.UIABSTRACT=" + getId());
while (resultset.next()) {
final long userId = resultset.getLong(1);
final AbstractUserObject userObject = AbstractUserObject.getUserObject(userId);
if (userObject == null) {
throw new CacheReloadException("user " + userId + " does not exists!");
} else {
getAccess().add(userId);
}
}
resultset.close();
} catch (final SQLException e) {
throw new CacheReloadException("could not read access for " + "'" + getName() + "'", e);
} catch (final EFapsException e) {
throw new CacheReloadException("could not read access for " + "'" + getName() + "'", e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (final SQLException e) {
throw new CacheReloadException("could not read access for " + "'" + getName() + "'", e);
}
}
}
} | [
"private",
"void",
"readFromDB4Access",
"(",
")",
"throws",
"CacheReloadException",
"{",
"Statement",
"stmt",
"=",
"null",
";",
"try",
"{",
"stmt",
"=",
"Context",
".",
"getThreadContext",
"(",
")",
".",
"getConnectionResource",
"(",
")",
".",
"createStatement",... | The instance method reads the access for this user interface object.
@throws CacheReloadException on error during reload | [
"The",
"instance",
"method",
"reads",
"the",
"access",
"for",
"this",
"user",
"interface",
"object",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/admin/ui/AbstractUserInterfaceObject.java#L147-L180 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/stmt/selection/elements/AbstractElement.java | AbstractElement.getPath | public String getPath()
{
final StringBuilder path = new StringBuilder();
if (getPrevious() != null) {
path.append(getPrevious().getPath());
}
return path.toString();
} | java | public String getPath()
{
final StringBuilder path = new StringBuilder();
if (getPrevious() != null) {
path.append(getPrevious().getPath());
}
return path.toString();
} | [
"public",
"String",
"getPath",
"(",
")",
"{",
"final",
"StringBuilder",
"path",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"if",
"(",
"getPrevious",
"(",
")",
"!=",
"null",
")",
"{",
"path",
".",
"append",
"(",
"getPrevious",
"(",
")",
".",
"getPath",... | Gets the path.
@return the path
@throws EFapsException the eFaps exception | [
"Gets",
"the",
"path",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/stmt/selection/elements/AbstractElement.java#L78-L85 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/eql/PrintStmt.java | PrintStmt.getEsjpSelect | private Map<String, IEsjpSelect> getEsjpSelect(final List<Instance> _instances)
throws Exception
{
final Map<String, IEsjpSelect> ret = new HashMap<>();
if (!_instances.isEmpty()) {
for (final Entry<String, AbstractSelect> entry : getAlias2Selects().entrySet()) {
if (entry.getValue() instanceof ExecSelect) {
final Class<?> clazz = Class.forName(entry.getValue().getSelect(), false, EFapsClassLoader
.getInstance());
final IEsjpSelect esjp = (IEsjpSelect) clazz.newInstance();
final List<String> parameters = ((ExecSelect) entry.getValue()).getParameters();
if (parameters.isEmpty()) {
esjp.initialize(_instances);
} else {
esjp.initialize(_instances, parameters.toArray(new String[parameters.size()]));
}
ret.put(entry.getKey(), esjp);
}
}
}
return ret;
} | java | private Map<String, IEsjpSelect> getEsjpSelect(final List<Instance> _instances)
throws Exception
{
final Map<String, IEsjpSelect> ret = new HashMap<>();
if (!_instances.isEmpty()) {
for (final Entry<String, AbstractSelect> entry : getAlias2Selects().entrySet()) {
if (entry.getValue() instanceof ExecSelect) {
final Class<?> clazz = Class.forName(entry.getValue().getSelect(), false, EFapsClassLoader
.getInstance());
final IEsjpSelect esjp = (IEsjpSelect) clazz.newInstance();
final List<String> parameters = ((ExecSelect) entry.getValue()).getParameters();
if (parameters.isEmpty()) {
esjp.initialize(_instances);
} else {
esjp.initialize(_instances, parameters.toArray(new String[parameters.size()]));
}
ret.put(entry.getKey(), esjp);
}
}
}
return ret;
} | [
"private",
"Map",
"<",
"String",
",",
"IEsjpSelect",
">",
"getEsjpSelect",
"(",
"final",
"List",
"<",
"Instance",
">",
"_instances",
")",
"throws",
"Exception",
"{",
"final",
"Map",
"<",
"String",
",",
"IEsjpSelect",
">",
"ret",
"=",
"new",
"HashMap",
"<>"... | Gets the esjp select.
@param _instances the _instances
@return the esjp select
@throws Exception the exception | [
"Gets",
"the",
"esjp",
"select",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/eql/PrintStmt.java#L86-L107 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/eql/PrintStmt.java | PrintStmt.getMultiPrint | private MultiPrintQuery getMultiPrint()
throws EFapsException
{
final MultiPrintQuery ret;
if (getInstances().isEmpty()) {
ret = new MultiPrintQuery(QueryBldrUtil.getInstances(this));
} else {
final List<Instance> instances = new ArrayList<>();
for (final String oid : getInstances()) {
instances.add(Instance.get(oid));
}
ret = new MultiPrintQuery(instances);
}
return ret;
} | java | private MultiPrintQuery getMultiPrint()
throws EFapsException
{
final MultiPrintQuery ret;
if (getInstances().isEmpty()) {
ret = new MultiPrintQuery(QueryBldrUtil.getInstances(this));
} else {
final List<Instance> instances = new ArrayList<>();
for (final String oid : getInstances()) {
instances.add(Instance.get(oid));
}
ret = new MultiPrintQuery(instances);
}
return ret;
} | [
"private",
"MultiPrintQuery",
"getMultiPrint",
"(",
")",
"throws",
"EFapsException",
"{",
"final",
"MultiPrintQuery",
"ret",
";",
"if",
"(",
"getInstances",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"ret",
"=",
"new",
"MultiPrintQuery",
"(",
"QueryBldrUtil... | Gets the multi print.
@return the multi print
@throws EFapsException on error | [
"Gets",
"the",
"multi",
"print",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/eql/PrintStmt.java#L115-L129 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/admin/datamodel/Dimension.java | Dimension.addUoM | private void addUoM(final UoM _uom)
{
this.uoMs.add(_uom);
if (_uom.getId() == this.baseUoMId) {
this.baseUoM = _uom;
}
} | java | private void addUoM(final UoM _uom)
{
this.uoMs.add(_uom);
if (_uom.getId() == this.baseUoMId) {
this.baseUoM = _uom;
}
} | [
"private",
"void",
"addUoM",
"(",
"final",
"UoM",
"_uom",
")",
"{",
"this",
".",
"uoMs",
".",
"add",
"(",
"_uom",
")",
";",
"if",
"(",
"_uom",
".",
"getId",
"(",
")",
"==",
"this",
".",
"baseUoMId",
")",
"{",
"this",
".",
"baseUoM",
"=",
"_uom",
... | Method to add an UoM to this dimension.
@param _uom UoM to add | [
"Method",
"to",
"add",
"an",
"UoM",
"to",
"this",
"dimension",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/admin/datamodel/Dimension.java#L196-L202 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/admin/datamodel/Dimension.java | Dimension.getUoM | public static UoM getUoM(final Long _uoMId)
{
final Cache<Long, UoM> cache = InfinispanCache.get().<Long, UoM>getCache(Dimension.IDCACHE4UOM);
if (!cache.containsKey(_uoMId)) {
try {
Dimension.getUoMFromDB(Dimension.SQL_SELECT_UOM4ID, _uoMId);
} catch (final CacheReloadException e) {
Dimension.LOG.error("read UoM from DB failed for id: '{}'", _uoMId);
}
}
return cache.get(_uoMId);
} | java | public static UoM getUoM(final Long _uoMId)
{
final Cache<Long, UoM> cache = InfinispanCache.get().<Long, UoM>getCache(Dimension.IDCACHE4UOM);
if (!cache.containsKey(_uoMId)) {
try {
Dimension.getUoMFromDB(Dimension.SQL_SELECT_UOM4ID, _uoMId);
} catch (final CacheReloadException e) {
Dimension.LOG.error("read UoM from DB failed for id: '{}'", _uoMId);
}
}
return cache.get(_uoMId);
} | [
"public",
"static",
"UoM",
"getUoM",
"(",
"final",
"Long",
"_uoMId",
")",
"{",
"final",
"Cache",
"<",
"Long",
",",
"UoM",
">",
"cache",
"=",
"InfinispanCache",
".",
"get",
"(",
")",
".",
"<",
"Long",
",",
"UoM",
">",
"getCache",
"(",
"Dimension",
"."... | Static Method to get an UoM for an id.
@param _uoMId if the UoM is wanted for.
@return UoM | [
"Static",
"Method",
"to",
"get",
"an",
"UoM",
"for",
"an",
"id",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/admin/datamodel/Dimension.java#L330-L341 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRResult.java | LRResult.getResumptionToken | public String getResumptionToken()
{
String resumptionToken = null;
try
{
if (data != null && data.has(resumptionTokenParam))
{
resumptionToken = data.getString(resumptionTokenParam);
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return resumptionToken;
} | java | public String getResumptionToken()
{
String resumptionToken = null;
try
{
if (data != null && data.has(resumptionTokenParam))
{
resumptionToken = data.getString(resumptionTokenParam);
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return resumptionToken;
} | [
"public",
"String",
"getResumptionToken",
"(",
")",
"{",
"String",
"resumptionToken",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"data",
"!=",
"null",
"&&",
"data",
".",
"has",
"(",
"resumptionTokenParam",
")",
")",
"{",
"resumptionToken",
"=",
"data",
".",
... | Returns the resumption token, if it exists
@return resumption token or null | [
"Returns",
"the",
"resumption",
"token",
"if",
"it",
"exists"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRResult.java#L70-L87 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRResult.java | LRResult.getResourceData | public List<JSONObject> getResourceData()
{
List<JSONObject> resources = new ArrayList<JSONObject>();
try
{
if (data != null && data.has(documentsParam))
{
List<JSONObject> results = getDocuments();
for(JSONObject json : results)
{
if (json.has(documentParam))
{
JSONObject result = json.getJSONObject(documentParam);
results.add(result);
}
}
}
else if (data != null && data.has(getRecordParam))
{
List<JSONObject> results = getRecords();
for(JSONObject json : results)
{
if (json.has(resourceDataParam))
{
JSONObject result = json.getJSONObject(resourceDataParam);
results.add(result);
}
}
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return resources;
} | java | public List<JSONObject> getResourceData()
{
List<JSONObject> resources = new ArrayList<JSONObject>();
try
{
if (data != null && data.has(documentsParam))
{
List<JSONObject> results = getDocuments();
for(JSONObject json : results)
{
if (json.has(documentParam))
{
JSONObject result = json.getJSONObject(documentParam);
results.add(result);
}
}
}
else if (data != null && data.has(getRecordParam))
{
List<JSONObject> results = getRecords();
for(JSONObject json : results)
{
if (json.has(resourceDataParam))
{
JSONObject result = json.getJSONObject(resourceDataParam);
results.add(result);
}
}
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return resources;
} | [
"public",
"List",
"<",
"JSONObject",
">",
"getResourceData",
"(",
")",
"{",
"List",
"<",
"JSONObject",
">",
"resources",
"=",
"new",
"ArrayList",
"<",
"JSONObject",
">",
"(",
")",
";",
"try",
"{",
"if",
"(",
"data",
"!=",
"null",
"&&",
"data",
".",
"... | Returns resource data from obtain or harvest request
@return list of resource data as JSON | [
"Returns",
"resource",
"data",
"from",
"obtain",
"or",
"harvest",
"request"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRResult.java#L94-L133 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRResult.java | LRResult.getDocuments | public List<JSONObject> getDocuments()
{
List<JSONObject> documents = new ArrayList<JSONObject>();
try
{
if (data != null && data.has(documentsParam))
{
JSONArray jsonDocuments = data.getJSONArray(documentsParam);
for(int i = 0; i < jsonDocuments.length(); i++)
{
JSONObject document = jsonDocuments.getJSONObject(i);
documents.add(document);
}
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return documents;
} | java | public List<JSONObject> getDocuments()
{
List<JSONObject> documents = new ArrayList<JSONObject>();
try
{
if (data != null && data.has(documentsParam))
{
JSONArray jsonDocuments = data.getJSONArray(documentsParam);
for(int i = 0; i < jsonDocuments.length(); i++)
{
JSONObject document = jsonDocuments.getJSONObject(i);
documents.add(document);
}
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return documents;
} | [
"public",
"List",
"<",
"JSONObject",
">",
"getDocuments",
"(",
")",
"{",
"List",
"<",
"JSONObject",
">",
"documents",
"=",
"new",
"ArrayList",
"<",
"JSONObject",
">",
"(",
")",
";",
"try",
"{",
"if",
"(",
"data",
"!=",
"null",
"&&",
"data",
".",
"has... | Returns documents from obtain request
@return documents from obtain request | [
"Returns",
"documents",
"from",
"obtain",
"request"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRResult.java#L140-L163 | train |
navnorth/LRJavaLib | src/com/navnorth/learningregistry/LRResult.java | LRResult.getRecords | public List<JSONObject> getRecords()
{
List<JSONObject> records = new ArrayList<JSONObject>();
try
{
if (data != null && data.has(getRecordParam))
{
JSONObject jsonGetRecord = data.getJSONObject(getRecordParam);
if (jsonGetRecord.has(recordParam))
{
JSONArray jsonRecords = jsonGetRecord.getJSONArray(recordParam);
for(int i = 0; i < jsonRecords.length(); i++)
{
JSONObject record = jsonRecords.getJSONObject(i);
records.add(record);
}
}
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return records;
} | java | public List<JSONObject> getRecords()
{
List<JSONObject> records = new ArrayList<JSONObject>();
try
{
if (data != null && data.has(getRecordParam))
{
JSONObject jsonGetRecord = data.getJSONObject(getRecordParam);
if (jsonGetRecord.has(recordParam))
{
JSONArray jsonRecords = jsonGetRecord.getJSONArray(recordParam);
for(int i = 0; i < jsonRecords.length(); i++)
{
JSONObject record = jsonRecords.getJSONObject(i);
records.add(record);
}
}
}
}
catch (JSONException e)
{
//This is already handled by the enclosing "has" checks
}
return records;
} | [
"public",
"List",
"<",
"JSONObject",
">",
"getRecords",
"(",
")",
"{",
"List",
"<",
"JSONObject",
">",
"records",
"=",
"new",
"ArrayList",
"<",
"JSONObject",
">",
"(",
")",
";",
"try",
"{",
"if",
"(",
"data",
"!=",
"null",
"&&",
"data",
".",
"has",
... | Returns records from harvest request
@return records from harvest request | [
"Returns",
"records",
"from",
"harvest",
"request"
] | 27af28b9f80d772273592414e7d0dccffaac09e1 | https://github.com/navnorth/LRJavaLib/blob/27af28b9f80d772273592414e7d0dccffaac09e1/src/com/navnorth/learningregistry/LRResult.java#L170-L198 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.roundBigDecimal | public BigDecimal roundBigDecimal(final BigDecimal number) {
int mscale = getMathScale();
if (mscale >= 0) {
return number.setScale(mscale, getMathContext().getRoundingMode());
}
else {
return number;
}
} | java | public BigDecimal roundBigDecimal(final BigDecimal number) {
int mscale = getMathScale();
if (mscale >= 0) {
return number.setScale(mscale, getMathContext().getRoundingMode());
}
else {
return number;
}
} | [
"public",
"BigDecimal",
"roundBigDecimal",
"(",
"final",
"BigDecimal",
"number",
")",
"{",
"int",
"mscale",
"=",
"getMathScale",
"(",
")",
";",
"if",
"(",
"mscale",
">=",
"0",
")",
"{",
"return",
"number",
".",
"setScale",
"(",
"mscale",
",",
"getMathConte... | Ensure a big decimal is rounded by this arithmetic scale and rounding mode.
@param number
the big decimal to round
@return the rounded big decimal | [
"Ensure",
"a",
"big",
"decimal",
"is",
"rounded",
"by",
"this",
"arithmetic",
"scale",
"and",
"rounding",
"mode",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L100-L108 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.isFloatingPointType | protected boolean isFloatingPointType(Object left, Object right) {
return left instanceof Float || left instanceof Double || right instanceof Float || right instanceof Double;
} | java | protected boolean isFloatingPointType(Object left, Object right) {
return left instanceof Float || left instanceof Double || right instanceof Float || right instanceof Double;
} | [
"protected",
"boolean",
"isFloatingPointType",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"return",
"left",
"instanceof",
"Float",
"||",
"left",
"instanceof",
"Double",
"||",
"right",
"instanceof",
"Float",
"||",
"right",
"instanceof",
"Double",
";... | Test if either left or right are either a Float or Double.
@param left
one object to test
@param right
the other
@return the result of the test. | [
"Test",
"if",
"either",
"left",
"or",
"right",
"are",
"either",
"a",
"Float",
"or",
"Double",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L119-L121 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.isNumberable | protected boolean isNumberable(final Object o) {
return o instanceof Integer || o instanceof Long || o instanceof Byte || o instanceof Short || o instanceof Character;
} | java | protected boolean isNumberable(final Object o) {
return o instanceof Integer || o instanceof Long || o instanceof Byte || o instanceof Short || o instanceof Character;
} | [
"protected",
"boolean",
"isNumberable",
"(",
"final",
"Object",
"o",
")",
"{",
"return",
"o",
"instanceof",
"Integer",
"||",
"o",
"instanceof",
"Long",
"||",
"o",
"instanceof",
"Byte",
"||",
"o",
"instanceof",
"Short",
"||",
"o",
"instanceof",
"Character",
"... | Is Object a whole number.
@param o
Object to be analyzed.
@return true if Integer, Long, Byte, Short or Character. | [
"Is",
"Object",
"a",
"whole",
"number",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L160-L162 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.narrowBigDecimal | protected Number narrowBigDecimal(Object lhs, Object rhs, BigDecimal bigd) {
if (isNumberable(lhs) || isNumberable(rhs)) {
try {
long l = bigd.longValueExact();
// coerce to int when possible (int being so often used in method parms)
if (l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) {
return Integer.valueOf((int) l);
}
else {
return Long.valueOf(l);
}
}
catch (ArithmeticException xa) {
// ignore, no exact value possible
}
}
return bigd;
} | java | protected Number narrowBigDecimal(Object lhs, Object rhs, BigDecimal bigd) {
if (isNumberable(lhs) || isNumberable(rhs)) {
try {
long l = bigd.longValueExact();
// coerce to int when possible (int being so often used in method parms)
if (l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) {
return Integer.valueOf((int) l);
}
else {
return Long.valueOf(l);
}
}
catch (ArithmeticException xa) {
// ignore, no exact value possible
}
}
return bigd;
} | [
"protected",
"Number",
"narrowBigDecimal",
"(",
"Object",
"lhs",
",",
"Object",
"rhs",
",",
"BigDecimal",
"bigd",
")",
"{",
"if",
"(",
"isNumberable",
"(",
"lhs",
")",
"||",
"isNumberable",
"(",
"rhs",
")",
")",
"{",
"try",
"{",
"long",
"l",
"=",
"bigd... | Given a BigDecimal, attempt to narrow it to an Integer or Long if it fits
if one of the arguments is a numberable.
@param lhs
the left hand side operand that lead to the bigd result
@param rhs
the right hand side operand that lead to the bigd result
@param bigd
the BigDecimal to narrow
@return an Integer or Long if narrowing is possible, the original
BigInteger otherwise | [
"Given",
"a",
"BigDecimal",
"attempt",
"to",
"narrow",
"it",
"to",
"an",
"Integer",
"or",
"Long",
"if",
"it",
"fits",
"if",
"one",
"of",
"the",
"arguments",
"is",
"a",
"numberable",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L208-L225 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.narrowArguments | protected boolean narrowArguments(Object[] args) {
boolean narrowed = false;
for (int a = 0; a < args.length; ++a) {
Object arg = args[a];
if (arg instanceof Number) {
Object narg = narrow((Number) arg);
if (narg != arg) {
narrowed = true;
}
args[a] = narg;
}
}
return narrowed;
} | java | protected boolean narrowArguments(Object[] args) {
boolean narrowed = false;
for (int a = 0; a < args.length; ++a) {
Object arg = args[a];
if (arg instanceof Number) {
Object narg = narrow((Number) arg);
if (narg != arg) {
narrowed = true;
}
args[a] = narg;
}
}
return narrowed;
} | [
"protected",
"boolean",
"narrowArguments",
"(",
"Object",
"[",
"]",
"args",
")",
"{",
"boolean",
"narrowed",
"=",
"false",
";",
"for",
"(",
"int",
"a",
"=",
"0",
";",
"a",
"<",
"args",
".",
"length",
";",
"++",
"a",
")",
"{",
"Object",
"arg",
"=",
... | Replace all numbers in an arguments array with the smallest type that will
fit.
@param args
the argument array
@return true if some arguments were narrowed and args array is modified,
false if no narrowing occured and args array has not been modified | [
"Replace",
"all",
"numbers",
"in",
"an",
"arguments",
"array",
"with",
"the",
"smallest",
"type",
"that",
"will",
"fit",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L311-L324 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.divide | public Object divide(Object left, Object right) {
if (left == null && right == null) {
return 0;
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
double l = toDouble(left);
double r = toDouble(right);
if (r == 0.0) {
throw new ArithmeticException("/");
}
return new Double(l / r);
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
if (BigDecimal.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
BigDecimal result = l.divide(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// otherwise treat as integers
BigInteger l = toBigInteger(left);
BigInteger r = toBigInteger(right);
if (BigInteger.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
BigInteger result = l.divide(r);
return narrowBigInteger(left, right, result);
} | java | public Object divide(Object left, Object right) {
if (left == null && right == null) {
return 0;
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
double l = toDouble(left);
double r = toDouble(right);
if (r == 0.0) {
throw new ArithmeticException("/");
}
return new Double(l / r);
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
if (BigDecimal.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
BigDecimal result = l.divide(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// otherwise treat as integers
BigInteger l = toBigInteger(left);
BigInteger r = toBigInteger(right);
if (BigInteger.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
BigInteger result = l.divide(r);
return narrowBigInteger(left, right, result);
} | [
"public",
"Object",
"divide",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"if",
"(",
"left",
"==",
"null",
"&&",
"right",
"==",
"null",
")",
"{",
"return",
"0",
";",
"}",
"// if either are floating point (double or float) use double",
"if",
"(",
... | Divide the left value by the right.
@param left
first value
@param right
second value
@return left / right
@throws ArithmeticException
if right == 0 | [
"Divide",
"the",
"left",
"value",
"by",
"the",
"right",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L408-L442 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.multiply | public Object multiply(Object left, Object right) {
if (left == null && right == null) {
return 0;
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
double l = toDouble(left);
double r = toDouble(right);
return new Double(l * r);
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
BigDecimal result = l.multiply(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// otherwise treat as integers
BigInteger l = toBigInteger(left);
BigInteger r = toBigInteger(right);
BigInteger result = l.multiply(r);
return narrowBigInteger(left, right, result);
} | java | public Object multiply(Object left, Object right) {
if (left == null && right == null) {
return 0;
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
double l = toDouble(left);
double r = toDouble(right);
return new Double(l * r);
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
BigDecimal result = l.multiply(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// otherwise treat as integers
BigInteger l = toBigInteger(left);
BigInteger r = toBigInteger(right);
BigInteger result = l.multiply(r);
return narrowBigInteger(left, right, result);
} | [
"public",
"Object",
"multiply",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"if",
"(",
"left",
"==",
"null",
"&&",
"right",
"==",
"null",
")",
"{",
"return",
"0",
";",
"}",
"// if either are floating point (double or float) use double",
"if",
"(",... | Multiply the left value by the right.
@param left
first value
@param right
second value
@return left * right. | [
"Multiply",
"the",
"left",
"value",
"by",
"the",
"right",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L500-L525 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.matches | public boolean matches(Object left, Object right) {
if (left == null && right == null) {
// if both are null L == R
return true;
}
if (left == null || right == null) {
// we know both aren't null, therefore L != R
return false;
}
final String arg = left.toString();
if (right instanceof java.util.regex.Pattern) {
return ((java.util.regex.Pattern) right).matcher(arg).matches();
}
else {
return arg.matches(right.toString());
}
} | java | public boolean matches(Object left, Object right) {
if (left == null && right == null) {
// if both are null L == R
return true;
}
if (left == null || right == null) {
// we know both aren't null, therefore L != R
return false;
}
final String arg = left.toString();
if (right instanceof java.util.regex.Pattern) {
return ((java.util.regex.Pattern) right).matcher(arg).matches();
}
else {
return arg.matches(right.toString());
}
} | [
"public",
"boolean",
"matches",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"if",
"(",
"left",
"==",
"null",
"&&",
"right",
"==",
"null",
")",
"{",
"// if both are null L == R",
"return",
"true",
";",
"}",
"if",
"(",
"left",
"==",
"null",
... | Test if left regexp matches right.
@param left
first value
@param right
second value
@return test result. | [
"Test",
"if",
"left",
"regexp",
"matches",
"right",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L618-L634 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.bitwiseOr | public Object bitwiseOr(Object left, Object right) {
long l = toLong(left);
long r = toLong(right);
return Long.valueOf(l | r);
} | java | public Object bitwiseOr(Object left, Object right) {
long l = toLong(left);
long r = toLong(right);
return Long.valueOf(l | r);
} | [
"public",
"Object",
"bitwiseOr",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"long",
"l",
"=",
"toLong",
"(",
"left",
")",
";",
"long",
"r",
"=",
"toLong",
"(",
"right",
")",
";",
"return",
"Long",
".",
"valueOf",
"(",
"l",
"|",
"r",
... | Performs a bitwise or.
@param left
the left operand
@param right
the right operator
@return left | right | [
"Performs",
"a",
"bitwise",
"or",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L660-L664 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.bitwiseComplement | public Object bitwiseComplement(Object val) {
long l = toLong(val);
return Long.valueOf(~l);
} | java | public Object bitwiseComplement(Object val) {
long l = toLong(val);
return Long.valueOf(~l);
} | [
"public",
"Object",
"bitwiseComplement",
"(",
"Object",
"val",
")",
"{",
"long",
"l",
"=",
"toLong",
"(",
"val",
")",
";",
"return",
"Long",
".",
"valueOf",
"(",
"~",
"l",
")",
";",
"}"
] | Performs a bitwise complement.
@param val
the operand
@return ~val | [
"Performs",
"a",
"bitwise",
"complement",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L688-L691 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.lessThan | public boolean lessThan(Object left, Object right) {
if ((left == right) || (left == null) || (right == null)) {
return false;
}
else {
return compare(left, right, "<") < 0;
}
} | java | public boolean lessThan(Object left, Object right) {
if ((left == right) || (left == null) || (right == null)) {
return false;
}
else {
return compare(left, right, "<") < 0;
}
} | [
"public",
"boolean",
"lessThan",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"if",
"(",
"(",
"left",
"==",
"right",
")",
"||",
"(",
"left",
"==",
"null",
")",
"||",
"(",
"right",
"==",
"null",
")",
")",
"{",
"return",
"false",
";",
"... | Test if left < right.
@param left
first value
@param right
second value
@return test result. | [
"Test",
"if",
"left",
"<",
"right",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L814-L822 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.greaterThan | public boolean greaterThan(Object left, Object right) {
if ((left == right) || left == null || right == null) {
return false;
}
else {
return compare(left, right, ">") > 0;
}
} | java | public boolean greaterThan(Object left, Object right) {
if ((left == right) || left == null || right == null) {
return false;
}
else {
return compare(left, right, ">") > 0;
}
} | [
"public",
"boolean",
"greaterThan",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"if",
"(",
"(",
"left",
"==",
"right",
")",
"||",
"left",
"==",
"null",
"||",
"right",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"r... | Test if left > right.
@param left
first value
@param right
second value
@return test result. | [
"Test",
"if",
"left",
">",
"right",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L833-L840 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.lessThanOrEqual | public boolean lessThanOrEqual(Object left, Object right) {
if (left == right) {
return true;
}
else if (left == null || right == null) {
return false;
}
else {
return compare(left, right, "<=") <= 0;
}
} | java | public boolean lessThanOrEqual(Object left, Object right) {
if (left == right) {
return true;
}
else if (left == null || right == null) {
return false;
}
else {
return compare(left, right, "<=") <= 0;
}
} | [
"public",
"boolean",
"lessThanOrEqual",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"if",
"(",
"left",
"==",
"right",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"left",
"==",
"null",
"||",
"right",
"==",
"null",
")",
"{",
... | Test if left <= right.
@param left
first value
@param right
second value
@return test result. | [
"Test",
"if",
"left",
"<",
"=",
"right",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L851-L861 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.greaterThanOrEqual | public boolean greaterThanOrEqual(Object left, Object right) {
if (left == right) {
return true;
}
else if (left == null || right == null) {
return false;
}
else {
return compare(left, right, ">=") >= 0;
}
} | java | public boolean greaterThanOrEqual(Object left, Object right) {
if (left == right) {
return true;
}
else if (left == null || right == null) {
return false;
}
else {
return compare(left, right, ">=") >= 0;
}
} | [
"public",
"boolean",
"greaterThanOrEqual",
"(",
"Object",
"left",
",",
"Object",
"right",
")",
"{",
"if",
"(",
"left",
"==",
"right",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"left",
"==",
"null",
"||",
"right",
"==",
"null",
")",
"{"... | Test if left >= right.
@param left
first value
@param right
second value
@return test result. | [
"Test",
"if",
"left",
">",
"=",
"right",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L872-L882 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.toInteger | public int toInteger(Object val) {
if (val == null) {
return 0;
}
else if (val instanceof Double) {
if (!Double.isNaN(((Double) val).doubleValue())) {
return 0;
}
else {
return ((Double) val).intValue();
}
}
else if (val instanceof Number) {
return ((Number) val).intValue();
}
else if (val instanceof String) {
if ("".equals(val)) {
return 0;
}
return Integer.parseInt((String) val);
}
else if (val instanceof Boolean) {
return ((Boolean) val).booleanValue() ? 1 : 0;
}
else if (val instanceof Character) {
return ((Character) val).charValue();
}
throw new ArithmeticException("Integer coercion: " + val.getClass().getName() + ":(" + val + ")");
} | java | public int toInteger(Object val) {
if (val == null) {
return 0;
}
else if (val instanceof Double) {
if (!Double.isNaN(((Double) val).doubleValue())) {
return 0;
}
else {
return ((Double) val).intValue();
}
}
else if (val instanceof Number) {
return ((Number) val).intValue();
}
else if (val instanceof String) {
if ("".equals(val)) {
return 0;
}
return Integer.parseInt((String) val);
}
else if (val instanceof Boolean) {
return ((Boolean) val).booleanValue() ? 1 : 0;
}
else if (val instanceof Character) {
return ((Character) val).charValue();
}
throw new ArithmeticException("Integer coercion: " + val.getClass().getName() + ":(" + val + ")");
} | [
"public",
"int",
"toInteger",
"(",
"Object",
"val",
")",
"{",
"if",
"(",
"val",
"==",
"null",
")",
"{",
"return",
"0",
";",
"}",
"else",
"if",
"(",
"val",
"instanceof",
"Double",
")",
"{",
"if",
"(",
"!",
"Double",
".",
"isNaN",
"(",
"(",
"(",
... | Coerce to a int.
@param val
Object to be coerced.
@return The int coerced value. | [
"Coerce",
"to",
"a",
"int",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L920-L949 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.toBigInteger | public BigInteger toBigInteger(Object val) {
if (val == null) {
return BigInteger.ZERO;
}
else if (val instanceof BigInteger) {
return (BigInteger) val;
}
else if (val instanceof Double) {
if (!Double.isNaN(((Double) val).doubleValue())) {
return new BigInteger(val.toString());
}
else {
return BigInteger.ZERO;
}
}
else if (val instanceof Number) {
return new BigInteger(val.toString());
}
else if (val instanceof String) {
String string = (String) val;
if ("".equals(string.trim())) {
return BigInteger.ZERO;
}
else {
return new BigInteger(string);
}
}
else if (val instanceof Character) {
int i = ((Character) val).charValue();
return BigInteger.valueOf(i);
}
throw new ArithmeticException("BigInteger coercion: " + val.getClass().getName() + ":(" + val + ")");
} | java | public BigInteger toBigInteger(Object val) {
if (val == null) {
return BigInteger.ZERO;
}
else if (val instanceof BigInteger) {
return (BigInteger) val;
}
else if (val instanceof Double) {
if (!Double.isNaN(((Double) val).doubleValue())) {
return new BigInteger(val.toString());
}
else {
return BigInteger.ZERO;
}
}
else if (val instanceof Number) {
return new BigInteger(val.toString());
}
else if (val instanceof String) {
String string = (String) val;
if ("".equals(string.trim())) {
return BigInteger.ZERO;
}
else {
return new BigInteger(string);
}
}
else if (val instanceof Character) {
int i = ((Character) val).charValue();
return BigInteger.valueOf(i);
}
throw new ArithmeticException("BigInteger coercion: " + val.getClass().getName() + ":(" + val + ")");
} | [
"public",
"BigInteger",
"toBigInteger",
"(",
"Object",
"val",
")",
"{",
"if",
"(",
"val",
"==",
"null",
")",
"{",
"return",
"BigInteger",
".",
"ZERO",
";",
"}",
"else",
"if",
"(",
"val",
"instanceof",
"BigInteger",
")",
"{",
"return",
"(",
"BigInteger",
... | Get a BigInteger from the object passed. Null and empty string maps to
zero.
@param val
the object to be coerced.
@return a BigDecimal.
@throws NullPointerException
if val is null and mode is strict. | [
"Get",
"a",
"BigInteger",
"from",
"the",
"object",
"passed",
".",
"Null",
"and",
"empty",
"string",
"maps",
"to",
"zero",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L1001-L1034 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.toBigDecimal | public BigDecimal toBigDecimal(Object val) {
if (val instanceof BigDecimal) {
return roundBigDecimal((BigDecimal) val);
}
else if (val == null) {
return BigDecimal.ZERO;
}
else if (val instanceof String) {
String string = ((String) val).trim();
if ("".equals(string)) {
return BigDecimal.ZERO;
}
return roundBigDecimal(new BigDecimal(string, getMathContext()));
}
else if (val instanceof Double) {
if (!Double.isNaN(((Double) val).doubleValue())) {
return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
}
else {
return BigDecimal.ZERO;
}
}
else if (val instanceof Number) {
return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
}
else if (val instanceof Character) {
int i = ((Character) val).charValue();
return new BigDecimal(i);
}
throw new ArithmeticException("BigDecimal coercion: " + val.getClass().getName() + ":(" + val + ")");
} | java | public BigDecimal toBigDecimal(Object val) {
if (val instanceof BigDecimal) {
return roundBigDecimal((BigDecimal) val);
}
else if (val == null) {
return BigDecimal.ZERO;
}
else if (val instanceof String) {
String string = ((String) val).trim();
if ("".equals(string)) {
return BigDecimal.ZERO;
}
return roundBigDecimal(new BigDecimal(string, getMathContext()));
}
else if (val instanceof Double) {
if (!Double.isNaN(((Double) val).doubleValue())) {
return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
}
else {
return BigDecimal.ZERO;
}
}
else if (val instanceof Number) {
return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
}
else if (val instanceof Character) {
int i = ((Character) val).charValue();
return new BigDecimal(i);
}
throw new ArithmeticException("BigDecimal coercion: " + val.getClass().getName() + ":(" + val + ")");
} | [
"public",
"BigDecimal",
"toBigDecimal",
"(",
"Object",
"val",
")",
"{",
"if",
"(",
"val",
"instanceof",
"BigDecimal",
")",
"{",
"return",
"roundBigDecimal",
"(",
"(",
"BigDecimal",
")",
"val",
")",
";",
"}",
"else",
"if",
"(",
"val",
"==",
"null",
")",
... | Get a BigDecimal from the object passed. Null and empty string maps to
zero.
@param val
the object to be coerced.
@return a BigDecimal.
@throws NullPointerException
if val is null and mode is strict. | [
"Get",
"a",
"BigDecimal",
"from",
"the",
"object",
"passed",
".",
"Null",
"and",
"empty",
"string",
"maps",
"to",
"zero",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L1046-L1077 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.toDouble | public double toDouble(Object val) {
if (val == null) {
return 0;
}
else if (val instanceof Double) {
return ((Double) val).doubleValue();
}
else if (val instanceof Number) {
// The below construct is used rather than ((Number)val).doubleValue() to ensure
// equality between comparing new Double( 6.4 / 3 ) and the stencil expression of 6.4 / 3
return Double.parseDouble(String.valueOf(val));
}
else if (val instanceof Boolean) {
return ((Boolean) val).booleanValue() ? 1. : 0.;
}
else if (val instanceof String) {
String string = ((String) val).trim();
if ("".equals(string)) {
return Double.NaN;
}
else {
// the spec seems to be iffy about this. Going to give it a wack anyway
return Double.parseDouble(string);
}
}
else if (val instanceof Character) {
int i = ((Character) val).charValue();
return i;
}
throw new ArithmeticException("Double coercion: " + val.getClass().getName() + ":(" + val + ")");
} | java | public double toDouble(Object val) {
if (val == null) {
return 0;
}
else if (val instanceof Double) {
return ((Double) val).doubleValue();
}
else if (val instanceof Number) {
// The below construct is used rather than ((Number)val).doubleValue() to ensure
// equality between comparing new Double( 6.4 / 3 ) and the stencil expression of 6.4 / 3
return Double.parseDouble(String.valueOf(val));
}
else if (val instanceof Boolean) {
return ((Boolean) val).booleanValue() ? 1. : 0.;
}
else if (val instanceof String) {
String string = ((String) val).trim();
if ("".equals(string)) {
return Double.NaN;
}
else {
// the spec seems to be iffy about this. Going to give it a wack anyway
return Double.parseDouble(string);
}
}
else if (val instanceof Character) {
int i = ((Character) val).charValue();
return i;
}
throw new ArithmeticException("Double coercion: " + val.getClass().getName() + ":(" + val + ")");
} | [
"public",
"double",
"toDouble",
"(",
"Object",
"val",
")",
"{",
"if",
"(",
"val",
"==",
"null",
")",
"{",
"return",
"0",
";",
"}",
"else",
"if",
"(",
"val",
"instanceof",
"Double",
")",
"{",
"return",
"(",
"(",
"Double",
")",
"val",
")",
".",
"do... | Coerce to a double.
@param val
Object to be coerced.
@return The double coerced value.
@throws NullPointerException
if val is null and mode is strict. | [
"Coerce",
"to",
"a",
"double",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L1088-L1119 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.toCollection | public Collection<?> toCollection(Object val) {
if (val == null) {
return Collections.emptyList();
}
else if (val instanceof Collection<?>) {
return (Collection<?>) val;
}
else if (val.getClass().isArray()) {
return newArrayList((Object[]) val);
}
else if (val instanceof Map<?,?>) {
return ((Map<?,?>)val).entrySet();
}
else {
return newArrayList(val);
}
} | java | public Collection<?> toCollection(Object val) {
if (val == null) {
return Collections.emptyList();
}
else if (val instanceof Collection<?>) {
return (Collection<?>) val;
}
else if (val.getClass().isArray()) {
return newArrayList((Object[]) val);
}
else if (val instanceof Map<?,?>) {
return ((Map<?,?>)val).entrySet();
}
else {
return newArrayList(val);
}
} | [
"public",
"Collection",
"<",
"?",
">",
"toCollection",
"(",
"Object",
"val",
")",
"{",
"if",
"(",
"val",
"==",
"null",
")",
"{",
"return",
"Collections",
".",
"emptyList",
"(",
")",
";",
"}",
"else",
"if",
"(",
"val",
"instanceof",
"Collection",
"<",
... | Coerce to a collection
@param val
Object to be coerced.
@return The Collection coerced value. | [
"Coerce",
"to",
"a",
"collection"
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L1153-L1170 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.narrowAccept | protected boolean narrowAccept(Class<?> narrow, Class<?> source) {
return narrow == null || narrow.equals(source);
} | java | protected boolean narrowAccept(Class<?> narrow, Class<?> source) {
return narrow == null || narrow.equals(source);
} | [
"protected",
"boolean",
"narrowAccept",
"(",
"Class",
"<",
"?",
">",
"narrow",
",",
"Class",
"<",
"?",
">",
"source",
")",
"{",
"return",
"narrow",
"==",
"null",
"||",
"narrow",
".",
"equals",
"(",
"source",
")",
";",
"}"
] | Whether we consider the narrow class as a potential candidate for narrowing
the source.
@param narrow
the target narrow class
@param source
the orginal source class
@return true if attempt to narrow source to target is accepted | [
"Whether",
"we",
"consider",
"the",
"narrow",
"class",
"as",
"a",
"potential",
"candidate",
"for",
"narrowing",
"the",
"source",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L1197-L1199 | train |
impossibl/stencil | engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java | StencilOperands.narrowNumber | protected Number narrowNumber(Number original, Class<?> narrow) {
if (original == null) {
return original;
}
Number result = original;
if (original instanceof BigDecimal) {
BigDecimal bigd = (BigDecimal) original;
// if it's bigger than a double it can't be narrowed
if (bigd.compareTo(BIGD_DOUBLE_MAX_VALUE) > 0) {
return original;
}
else {
try {
long l = bigd.longValueExact();
// coerce to int when possible (int being so often used in method
// parms)
if (narrowAccept(narrow, Integer.class) && l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) {
return Integer.valueOf((int) l);
}
else if (narrowAccept(narrow, Long.class)) {
return Long.valueOf(l);
}
}
catch (ArithmeticException xa) {
// ignore, no exact value possible
}
}
}
if (original instanceof Double || original instanceof Float || original instanceof BigDecimal) {
double value = original.doubleValue();
if (narrowAccept(narrow, Float.class) && value <= Float.MAX_VALUE && value >= Float.MIN_VALUE) {
result = Float.valueOf(result.floatValue());
}
// else it fits in a double only
}
else {
if (original instanceof BigInteger) {
BigInteger bigi = (BigInteger) original;
// if it's bigger than a Long it can't be narrowed
if (bigi.compareTo(BIGI_LONG_MAX_VALUE) > 0 || bigi.compareTo(BIGI_LONG_MIN_VALUE) < 0) {
return original;
}
}
long value = original.longValue();
if (narrowAccept(narrow, Byte.class) && value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE) {
// it will fit in a byte
result = Byte.valueOf((byte) value);
}
else if (narrowAccept(narrow, Short.class) && value <= Short.MAX_VALUE && value >= Short.MIN_VALUE) {
result = Short.valueOf((short) value);
}
else if (narrowAccept(narrow, Integer.class) && value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) {
result = Integer.valueOf((int) value);
}
// else it fits in a long
}
return result;
} | java | protected Number narrowNumber(Number original, Class<?> narrow) {
if (original == null) {
return original;
}
Number result = original;
if (original instanceof BigDecimal) {
BigDecimal bigd = (BigDecimal) original;
// if it's bigger than a double it can't be narrowed
if (bigd.compareTo(BIGD_DOUBLE_MAX_VALUE) > 0) {
return original;
}
else {
try {
long l = bigd.longValueExact();
// coerce to int when possible (int being so often used in method
// parms)
if (narrowAccept(narrow, Integer.class) && l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) {
return Integer.valueOf((int) l);
}
else if (narrowAccept(narrow, Long.class)) {
return Long.valueOf(l);
}
}
catch (ArithmeticException xa) {
// ignore, no exact value possible
}
}
}
if (original instanceof Double || original instanceof Float || original instanceof BigDecimal) {
double value = original.doubleValue();
if (narrowAccept(narrow, Float.class) && value <= Float.MAX_VALUE && value >= Float.MIN_VALUE) {
result = Float.valueOf(result.floatValue());
}
// else it fits in a double only
}
else {
if (original instanceof BigInteger) {
BigInteger bigi = (BigInteger) original;
// if it's bigger than a Long it can't be narrowed
if (bigi.compareTo(BIGI_LONG_MAX_VALUE) > 0 || bigi.compareTo(BIGI_LONG_MIN_VALUE) < 0) {
return original;
}
}
long value = original.longValue();
if (narrowAccept(narrow, Byte.class) && value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE) {
// it will fit in a byte
result = Byte.valueOf((byte) value);
}
else if (narrowAccept(narrow, Short.class) && value <= Short.MAX_VALUE && value >= Short.MIN_VALUE) {
result = Short.valueOf((short) value);
}
else if (narrowAccept(narrow, Integer.class) && value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) {
result = Integer.valueOf((int) value);
}
// else it fits in a long
}
return result;
} | [
"protected",
"Number",
"narrowNumber",
"(",
"Number",
"original",
",",
"Class",
"<",
"?",
">",
"narrow",
")",
"{",
"if",
"(",
"original",
"==",
"null",
")",
"{",
"return",
"original",
";",
"}",
"Number",
"result",
"=",
"original",
";",
"if",
"(",
"orig... | Given a Number, return back the value attempting to narrow it to a target
class.
@param original
the original number
@param narrow
the attempted target class
@return the narrowed number or the source if no narrowing was possible | [
"Given",
"a",
"Number",
"return",
"back",
"the",
"value",
"attempting",
"to",
"narrow",
"it",
"to",
"a",
"target",
"class",
"."
] | 4aac1be605542b4248be95bf8916be4e2f755d1c | https://github.com/impossibl/stencil/blob/4aac1be605542b4248be95bf8916be4e2f755d1c/engine/src/main/java/com/impossibl/stencil/engine/internal/StencilOperands.java#L1211-L1268 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/admin/datamodel/AttributeSet.java | AttributeSet.get | public static AttributeSet get(final String _typeName,
final String _name)
throws CacheReloadException
{
return (AttributeSet) Type.get(AttributeSet.evaluateName(_typeName, _name));
} | java | public static AttributeSet get(final String _typeName,
final String _name)
throws CacheReloadException
{
return (AttributeSet) Type.get(AttributeSet.evaluateName(_typeName, _name));
} | [
"public",
"static",
"AttributeSet",
"get",
"(",
"final",
"String",
"_typeName",
",",
"final",
"String",
"_name",
")",
"throws",
"CacheReloadException",
"{",
"return",
"(",
"AttributeSet",
")",
"Type",
".",
"get",
"(",
"AttributeSet",
".",
"evaluateName",
"(",
... | Method to get the type from the cache.
@param _typeName name of the type
@param _name name of the attribute
@return AttributeSet
@throws CacheReloadException on error | [
"Method",
"to",
"get",
"the",
"type",
"from",
"the",
"cache",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/admin/datamodel/AttributeSet.java#L179-L184 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/admin/datamodel/AttributeSet.java | AttributeSet.find | public static AttributeSet find(final String _typeName,
final String _name)
throws CacheReloadException
{
AttributeSet ret = (AttributeSet) Type.get(AttributeSet.evaluateName(_typeName, _name));
if (ret == null) {
if (Type.get(_typeName).getParentType() != null) {
ret = AttributeSet.find(Type.get(_typeName).getParentType().getName(), _name);
}
}
return ret;
} | java | public static AttributeSet find(final String _typeName,
final String _name)
throws CacheReloadException
{
AttributeSet ret = (AttributeSet) Type.get(AttributeSet.evaluateName(_typeName, _name));
if (ret == null) {
if (Type.get(_typeName).getParentType() != null) {
ret = AttributeSet.find(Type.get(_typeName).getParentType().getName(), _name);
}
}
return ret;
} | [
"public",
"static",
"AttributeSet",
"find",
"(",
"final",
"String",
"_typeName",
",",
"final",
"String",
"_name",
")",
"throws",
"CacheReloadException",
"{",
"AttributeSet",
"ret",
"=",
"(",
"AttributeSet",
")",
"Type",
".",
"get",
"(",
"AttributeSet",
".",
"e... | Method to get the type from the cache. Searches if not found in the type
hierarchy.
@param _typeName name of the type
@param _name name of the attribute
@return AttributeSet
@throws CacheReloadException on error | [
"Method",
"to",
"get",
"the",
"type",
"from",
"the",
"cache",
".",
"Searches",
"if",
"not",
"found",
"in",
"the",
"type",
"hierarchy",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/admin/datamodel/AttributeSet.java#L195-L206 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/print/value/ClassificationValueSelect.java | ClassificationValueSelect.getClassification | private Set<Classification> getClassification(final List<Long> _classIds)
throws CacheReloadException
{
final Set<Classification> noadd = new HashSet<>();
final Set<Classification> add = new HashSet<>();
if (_classIds != null) {
for (final Long id : _classIds) {
Classification clazz = (Classification) Type.get(id);
if (!noadd.contains(clazz)) {
add.add(clazz);
while (clazz.getParentClassification() != null) {
clazz = clazz.getParentClassification();
if (add.contains(clazz)) {
add.remove(clazz);
}
noadd.add(clazz);
}
}
}
}
return add;
} | java | private Set<Classification> getClassification(final List<Long> _classIds)
throws CacheReloadException
{
final Set<Classification> noadd = new HashSet<>();
final Set<Classification> add = new HashSet<>();
if (_classIds != null) {
for (final Long id : _classIds) {
Classification clazz = (Classification) Type.get(id);
if (!noadd.contains(clazz)) {
add.add(clazz);
while (clazz.getParentClassification() != null) {
clazz = clazz.getParentClassification();
if (add.contains(clazz)) {
add.remove(clazz);
}
noadd.add(clazz);
}
}
}
}
return add;
} | [
"private",
"Set",
"<",
"Classification",
">",
"getClassification",
"(",
"final",
"List",
"<",
"Long",
">",
"_classIds",
")",
"throws",
"CacheReloadException",
"{",
"final",
"Set",
"<",
"Classification",
">",
"noadd",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";... | Method to get only the leaf of the classification tree.
@param _classIds List of classids
@return set
@throws CacheReloadException on error | [
"Method",
"to",
"get",
"only",
"the",
"leaf",
"of",
"the",
"classification",
"tree",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/print/value/ClassificationValueSelect.java#L134-L155 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/print/value/ClassificationValueSelect.java | ClassificationValueSelect.executeOneCompleteStmt | protected boolean executeOneCompleteStmt(final String _complStmt,
final List<Instance> _instances)
throws EFapsException
{
final boolean ret = false;
ConnectionResource con = null;
try {
con = Context.getThreadContext().getConnectionResource();
final Statement stmt = con.createStatement();
final ResultSet rs = stmt.executeQuery(_complStmt.toString());
final Map<Long, List<Long>> link2clazz = new HashMap<>();
while (rs.next()) {
final long linkId = rs.getLong(2);
final long classificationID = rs.getLong(3);
final List<Long> templ;
if (link2clazz.containsKey(linkId)) {
templ = link2clazz.get(linkId);
} else {
templ = new ArrayList<>();
link2clazz.put(linkId, templ);
}
templ.add(classificationID);
}
for (final Instance instance : _instances) {
this.instances2classId.put(instance, link2clazz.get(instance.getId()));
}
rs.close();
stmt.close();
} catch (final SQLException e) {
throw new EFapsException(ClassificationValueSelect.class, "executeOneCompleteStmt", e);
}
return ret;
} | java | protected boolean executeOneCompleteStmt(final String _complStmt,
final List<Instance> _instances)
throws EFapsException
{
final boolean ret = false;
ConnectionResource con = null;
try {
con = Context.getThreadContext().getConnectionResource();
final Statement stmt = con.createStatement();
final ResultSet rs = stmt.executeQuery(_complStmt.toString());
final Map<Long, List<Long>> link2clazz = new HashMap<>();
while (rs.next()) {
final long linkId = rs.getLong(2);
final long classificationID = rs.getLong(3);
final List<Long> templ;
if (link2clazz.containsKey(linkId)) {
templ = link2clazz.get(linkId);
} else {
templ = new ArrayList<>();
link2clazz.put(linkId, templ);
}
templ.add(classificationID);
}
for (final Instance instance : _instances) {
this.instances2classId.put(instance, link2clazz.get(instance.getId()));
}
rs.close();
stmt.close();
} catch (final SQLException e) {
throw new EFapsException(ClassificationValueSelect.class, "executeOneCompleteStmt", e);
}
return ret;
} | [
"protected",
"boolean",
"executeOneCompleteStmt",
"(",
"final",
"String",
"_complStmt",
",",
"final",
"List",
"<",
"Instance",
">",
"_instances",
")",
"throws",
"EFapsException",
"{",
"final",
"boolean",
"ret",
"=",
"false",
";",
"ConnectionResource",
"con",
"=",
... | Method to execute one statement against the eFaps-DataBase.
@param _complStmt ststement
@param _instances list of instances
@return true it values where found
@throws EFapsException on error | [
"Method",
"to",
"execute",
"one",
"statement",
"against",
"the",
"eFaps",
"-",
"DataBase",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/print/value/ClassificationValueSelect.java#L259-L293 | train |
JavaKoan/koan-annotations | src/main/java/com/javakoan/fixture/io/KoanWriter.java | KoanWriter.writeSourceToFile | public static void writeSourceToFile(Class<?> koanClass, String newSource) {
Path currentRelativePath = Paths.get("");
String workingDirectory = currentRelativePath.toAbsolutePath().toString();
String packagePath = koanClass.getPackage().getName();
packagePath = packagePath.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
String className = koanClass.getSimpleName();
File file = new File(workingDirectory + KOAN_JAVA_PATH + packagePath + PATH_SEPARATOR + className + JAVA_EXTENSION);
try {
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(newSource);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
} | java | public static void writeSourceToFile(Class<?> koanClass, String newSource) {
Path currentRelativePath = Paths.get("");
String workingDirectory = currentRelativePath.toAbsolutePath().toString();
String packagePath = koanClass.getPackage().getName();
packagePath = packagePath.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
String className = koanClass.getSimpleName();
File file = new File(workingDirectory + KOAN_JAVA_PATH + packagePath + PATH_SEPARATOR + className + JAVA_EXTENSION);
try {
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(newSource);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
} | [
"public",
"static",
"void",
"writeSourceToFile",
"(",
"Class",
"<",
"?",
">",
"koanClass",
",",
"String",
"newSource",
")",
"{",
"Path",
"currentRelativePath",
"=",
"Paths",
".",
"get",
"(",
"\"\"",
")",
";",
"String",
"workingDirectory",
"=",
"currentRelative... | Write source to file.
@param koanClass the koan class
@param newSource the source code to be written | [
"Write",
"source",
"to",
"file",
"."
] | e3c4872ae57051a0b74b2efa6f15f4ee9e37d263 | https://github.com/JavaKoan/koan-annotations/blob/e3c4872ae57051a0b74b2efa6f15f4ee9e37d263/src/main/java/com/javakoan/fixture/io/KoanWriter.java#L47-L66 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/jaas/LoginHandler.java | LoginHandler.createPerson | protected Person createPerson(final LoginContext _login)
throws EFapsException
{
Person person = null;
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
final Set<?> users = _login.getSubject().getPrincipals(system.getPersonJAASPrincipleClass());
for (final Object persObj : users) {
try {
final String persKey = (String) system.getPersonMethodKey().invoke(persObj);
final String persName = (String) system.getPersonMethodName().invoke(persObj);
if (person == null) {
person = Person.createPerson(system, persKey, persName, null);
} else {
person.assignToJAASSystem(system, persKey);
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalAccessException", e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalArgumentException", e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "InvocationTargetException", e);
}
}
}
return person;
} | java | protected Person createPerson(final LoginContext _login)
throws EFapsException
{
Person person = null;
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
final Set<?> users = _login.getSubject().getPrincipals(system.getPersonJAASPrincipleClass());
for (final Object persObj : users) {
try {
final String persKey = (String) system.getPersonMethodKey().invoke(persObj);
final String persName = (String) system.getPersonMethodName().invoke(persObj);
if (person == null) {
person = Person.createPerson(system, persKey, persName, null);
} else {
person.assignToJAASSystem(system, persKey);
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalAccessException", e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalArgumentException", e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "InvocationTargetException", e);
}
}
}
return person;
} | [
"protected",
"Person",
"createPerson",
"(",
"final",
"LoginContext",
"_login",
")",
"throws",
"EFapsException",
"{",
"Person",
"person",
"=",
"null",
";",
"for",
"(",
"final",
"JAASSystem",
"system",
":",
"JAASSystem",
".",
"getAllJAASSystems",
"(",
")",
")",
... | The person represented in the JAAS login context is created and
associated to eFaps. If the person is defined in more than one JAAS
system, the person is also associated to the other JAAS systems.
@param _login JAAS login context
@return Java instance of newly created person
@throws EFapsException if a method of the principals inside the JAAS
login contexts could not be executed. | [
"The",
"person",
"represented",
"in",
"the",
"JAAS",
"login",
"context",
"is",
"created",
"and",
"associated",
"to",
"eFaps",
".",
"If",
"the",
"person",
"is",
"defined",
"in",
"more",
"than",
"one",
"JAAS",
"system",
"the",
"person",
"is",
"also",
"associ... | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/jaas/LoginHandler.java#L194-L224 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/jaas/LoginHandler.java | LoginHandler.updatePerson | protected void updatePerson(final LoginContext _login,
final Person _person)
throws EFapsException
{
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
final Set<?> users = _login.getSubject().getPrincipals(system.getPersonJAASPrincipleClass());
for (final Object persObj : users) {
try {
for (final Map.Entry<Person.AttrName, Method> entry
: system.getPersonMethodAttributes().entrySet()) {
_person.updateAttrValue(entry.getKey(), (String) entry.getValue().invoke(persObj));
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalAccessException", e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalArgumentException", e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "InvocationTargetException", e);
}
}
}
_person.commitAttrValuesInDB();
} | java | protected void updatePerson(final LoginContext _login,
final Person _person)
throws EFapsException
{
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
final Set<?> users = _login.getSubject().getPrincipals(system.getPersonJAASPrincipleClass());
for (final Object persObj : users) {
try {
for (final Map.Entry<Person.AttrName, Method> entry
: system.getPersonMethodAttributes().entrySet()) {
_person.updateAttrValue(entry.getKey(), (String) entry.getValue().invoke(persObj));
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalAccessException", e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "IllegalArgumentException", e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute a person method for system " + system.getName(), e);
throw new EFapsException(LoginHandler.class, "InvocationTargetException", e);
}
}
}
_person.commitAttrValuesInDB();
} | [
"protected",
"void",
"updatePerson",
"(",
"final",
"LoginContext",
"_login",
",",
"final",
"Person",
"_person",
")",
"throws",
"EFapsException",
"{",
"for",
"(",
"final",
"JAASSystem",
"system",
":",
"JAASSystem",
".",
"getAllJAASSystems",
"(",
")",
")",
"{",
... | The person information inside eFaps is update with information from JAAS
login context.
@param _login JAAS login context
@param _person Java person instance inside eFaps to update
@throws EFapsException if a method of the principals inside the JAAS
login contexts could not be executed or the
person could not be updated from the values in
the JAAS login context. | [
"The",
"person",
"information",
"inside",
"eFaps",
"is",
"update",
"with",
"information",
"from",
"JAAS",
"login",
"context",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/jaas/LoginHandler.java#L237-L262 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/jaas/LoginHandler.java | LoginHandler.updateRoles | protected void updateRoles(final LoginContext _login,
final Person _person)
throws EFapsException
{
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
if (system.getRoleJAASPrincipleClass() != null) {
final Set<?> rolesJaas = _login.getSubject().getPrincipals(system.getRoleJAASPrincipleClass());
final Set<Role> rolesEfaps = new HashSet<>();
for (final Object roleObj : rolesJaas) {
try {
final String roleKey = (String) system.getRoleMethodKey().invoke(roleObj);
final Role roleEfaps = Role.getWithJAASKey(system, roleKey);
if (roleEfaps != null) {
rolesEfaps.add(roleEfaps);
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute role key method for system " + system.getName(), e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute role key method for system " + system.getName(), e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute role key method for system " + system.getName(), e);
}
}
_person.setRoles(system, rolesEfaps);
}
}
} | java | protected void updateRoles(final LoginContext _login,
final Person _person)
throws EFapsException
{
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
if (system.getRoleJAASPrincipleClass() != null) {
final Set<?> rolesJaas = _login.getSubject().getPrincipals(system.getRoleJAASPrincipleClass());
final Set<Role> rolesEfaps = new HashSet<>();
for (final Object roleObj : rolesJaas) {
try {
final String roleKey = (String) system.getRoleMethodKey().invoke(roleObj);
final Role roleEfaps = Role.getWithJAASKey(system, roleKey);
if (roleEfaps != null) {
rolesEfaps.add(roleEfaps);
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute role key method for system " + system.getName(), e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute role key method for system " + system.getName(), e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute role key method for system " + system.getName(), e);
}
}
_person.setRoles(system, rolesEfaps);
}
}
} | [
"protected",
"void",
"updateRoles",
"(",
"final",
"LoginContext",
"_login",
",",
"final",
"Person",
"_person",
")",
"throws",
"EFapsException",
"{",
"for",
"(",
"final",
"JAASSystem",
"system",
":",
"JAASSystem",
".",
"getAllJAASSystems",
"(",
")",
")",
"{",
"... | The roles of the given person are updated with the information from the
JAAS login context.
@param _login JAAS login context
@param _person person for which the roles must be updated
@throws EFapsException if a method of the principals inside the JAAS
login contexts could not be executed or the roles
for the given person could not be set. | [
"The",
"roles",
"of",
"the",
"given",
"person",
"are",
"updated",
"with",
"the",
"information",
"from",
"the",
"JAAS",
"login",
"context",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/jaas/LoginHandler.java#L274-L300 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/jaas/LoginHandler.java | LoginHandler.updateGroups | protected void updateGroups(final LoginContext _login,
final Person _person)
throws EFapsException
{
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
if (system.getGroupJAASPrincipleClass() != null) {
final Set<?> groupsJaas = _login.getSubject().getPrincipals(system.getGroupJAASPrincipleClass());
final Set<Group> groupsEfaps = new HashSet<>();
for (final Object groupObj : groupsJaas) {
try {
final String groupKey = (String) system.getGroupMethodKey().invoke(groupObj);
final Group groupEfaps = Group.getWithJAASKey(system, groupKey);
if (groupEfaps != null) {
groupsEfaps.add(groupEfaps);
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute group key method for system " + system.getName(), e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute group key method for system " + system.getName(), e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute group key method for system " + system.getName(), e);
}
}
_person.setGroups(system, groupsEfaps);
}
}
} | java | protected void updateGroups(final LoginContext _login,
final Person _person)
throws EFapsException
{
for (final JAASSystem system : JAASSystem.getAllJAASSystems()) {
if (system.getGroupJAASPrincipleClass() != null) {
final Set<?> groupsJaas = _login.getSubject().getPrincipals(system.getGroupJAASPrincipleClass());
final Set<Group> groupsEfaps = new HashSet<>();
for (final Object groupObj : groupsJaas) {
try {
final String groupKey = (String) system.getGroupMethodKey().invoke(groupObj);
final Group groupEfaps = Group.getWithJAASKey(system, groupKey);
if (groupEfaps != null) {
groupsEfaps.add(groupEfaps);
}
} catch (final IllegalAccessException e) {
LoginHandler.LOG.error("could not execute group key method for system " + system.getName(), e);
} catch (final IllegalArgumentException e) {
LoginHandler.LOG.error("could not execute group key method for system " + system.getName(), e);
} catch (final InvocationTargetException e) {
LoginHandler.LOG.error("could not execute group key method for system " + system.getName(), e);
}
}
_person.setGroups(system, groupsEfaps);
}
}
} | [
"protected",
"void",
"updateGroups",
"(",
"final",
"LoginContext",
"_login",
",",
"final",
"Person",
"_person",
")",
"throws",
"EFapsException",
"{",
"for",
"(",
"final",
"JAASSystem",
"system",
":",
"JAASSystem",
".",
"getAllJAASSystems",
"(",
")",
")",
"{",
... | The groups of the given person are updated with the information from the
JAAS login context.
@param _login JAAS login context
@param _person person for which the groups must be updated
@throws EFapsException if a method of the principals inside the JAAS
login contexts could not be executed or the
groups for the given person could not be set. | [
"The",
"groups",
"of",
"the",
"given",
"person",
"are",
"updated",
"with",
"the",
"information",
"from",
"the",
"JAAS",
"login",
"context",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/jaas/LoginHandler.java#L312-L338 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/model/Attachment.java | Attachment.updateWithUploadDetails | public Attachment updateWithUploadDetails(UploadContentResponse response) {
this.id = response.getId();
this.url = response.getUrl();
this.size = response.getSize();
this.type = response.getType();
return this;
} | java | public Attachment updateWithUploadDetails(UploadContentResponse response) {
this.id = response.getId();
this.url = response.getUrl();
this.size = response.getSize();
this.type = response.getType();
return this;
} | [
"public",
"Attachment",
"updateWithUploadDetails",
"(",
"UploadContentResponse",
"response",
")",
"{",
"this",
".",
"id",
"=",
"response",
".",
"getId",
"(",
")",
";",
"this",
".",
"url",
"=",
"response",
".",
"getUrl",
"(",
")",
";",
"this",
".",
"size",
... | For internal use. Update attachment details with upload APIs response.
@param response Upload content APIs response.
@return Updated attachment. | [
"For",
"internal",
"use",
".",
"Update",
"attachment",
"details",
"with",
"upload",
"APIs",
"response",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/model/Attachment.java#L168-L174 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/databases/DerbyDatabase.java | DerbyDatabase.initTableInfoUniqueKeys | @Override
protected void initTableInfoUniqueKeys(final Connection _con,
final String _sql,
final Map<String, TableInformation> _cache4Name)
throws SQLException
{
final String sqlStmt = new StringBuilder()
.append("select t.tablename as TABLE_NAME, c.CONSTRAINTNAME as INDEX_NAME, g.DESCRIPTOR as COLUMN_NAME")
.append(" from SYS.SYSTABLES t, SYS.SYSCONSTRAINTS c, SYS.SYSKEYS k, SYS.SYSCONGLOMERATES g ")
.append(" where t.TABLEID=c.TABLEID")
.append(" AND c.TYPE='U'")
.append(" AND c.CONSTRAINTID = k.CONSTRAINTID")
.append(" AND k.CONGLOMERATEID = g.CONGLOMERATEID")
.toString();
super.initTableInfoUniqueKeys(_con, sqlStmt, _cache4Name);
} | java | @Override
protected void initTableInfoUniqueKeys(final Connection _con,
final String _sql,
final Map<String, TableInformation> _cache4Name)
throws SQLException
{
final String sqlStmt = new StringBuilder()
.append("select t.tablename as TABLE_NAME, c.CONSTRAINTNAME as INDEX_NAME, g.DESCRIPTOR as COLUMN_NAME")
.append(" from SYS.SYSTABLES t, SYS.SYSCONSTRAINTS c, SYS.SYSKEYS k, SYS.SYSCONGLOMERATES g ")
.append(" where t.TABLEID=c.TABLEID")
.append(" AND c.TYPE='U'")
.append(" AND c.CONSTRAINTID = k.CONSTRAINTID")
.append(" AND k.CONGLOMERATEID = g.CONGLOMERATEID")
.toString();
super.initTableInfoUniqueKeys(_con, sqlStmt, _cache4Name);
} | [
"@",
"Override",
"protected",
"void",
"initTableInfoUniqueKeys",
"(",
"final",
"Connection",
"_con",
",",
"final",
"String",
"_sql",
",",
"final",
"Map",
"<",
"String",
",",
"TableInformation",
">",
"_cache4Name",
")",
"throws",
"SQLException",
"{",
"final",
"St... | Fetches all unique keys for this table. Instead of using the JDBC
meta data functionality, a SQL statement on system tables are used,
because the JDBC meta data functionality returns for unique keys
internal names and not the real names. Also if a unique key includes
also columns with null values, this unique keys are not included.
@param _con Connection
@param _sql Statement
@param _cache4Name cache
@throws SQLException if unique keys could not be fetched | [
"Fetches",
"all",
"unique",
"keys",
"for",
"this",
"table",
".",
"Instead",
"of",
"using",
"the",
"JDBC",
"meta",
"data",
"functionality",
"a",
"SQL",
"statement",
"on",
"system",
"tables",
"are",
"used",
"because",
"the",
"JDBC",
"meta",
"data",
"functional... | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/databases/DerbyDatabase.java#L450-L465 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/store/VFSStoreResource.java | VFSStoreResource.backup | private void backup(final FileObject _backup,
final int _number)
throws FileSystemException
{
if (_number < this.numberBackup) {
final FileObject backFile = this.manager.resolveFile(this.manager.getBaseFile(),
this.storeFileName + VFSStoreResource.EXTENSION_BACKUP + _number);
if (backFile.exists()) {
backup(backFile, _number + 1);
}
_backup.moveTo(backFile);
} else {
_backup.delete();
}
} | java | private void backup(final FileObject _backup,
final int _number)
throws FileSystemException
{
if (_number < this.numberBackup) {
final FileObject backFile = this.manager.resolveFile(this.manager.getBaseFile(),
this.storeFileName + VFSStoreResource.EXTENSION_BACKUP + _number);
if (backFile.exists()) {
backup(backFile, _number + 1);
}
_backup.moveTo(backFile);
} else {
_backup.delete();
}
} | [
"private",
"void",
"backup",
"(",
"final",
"FileObject",
"_backup",
",",
"final",
"int",
"_number",
")",
"throws",
"FileSystemException",
"{",
"if",
"(",
"_number",
"<",
"this",
".",
"numberBackup",
")",
"{",
"final",
"FileObject",
"backFile",
"=",
"this",
"... | Method that deletes the oldest backup and moves the others one up.
@param _backup file to backup
@param _number number of backup
@throws FileSystemException on error | [
"Method",
"that",
"deletes",
"the",
"oldest",
"backup",
"and",
"moves",
"the",
"others",
"one",
"up",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/store/VFSStoreResource.java#L393-L407 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/store/VFSStoreResource.java | VFSStoreResource.recover | @Override
public Xid[] recover(final int _flag)
{
if (VFSStoreResource.LOG.isDebugEnabled()) {
VFSStoreResource.LOG.debug("recover (flag = " + _flag + ")");
}
return null;
} | java | @Override
public Xid[] recover(final int _flag)
{
if (VFSStoreResource.LOG.isDebugEnabled()) {
VFSStoreResource.LOG.debug("recover (flag = " + _flag + ")");
}
return null;
} | [
"@",
"Override",
"public",
"Xid",
"[",
"]",
"recover",
"(",
"final",
"int",
"_flag",
")",
"{",
"if",
"(",
"VFSStoreResource",
".",
"LOG",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"VFSStoreResource",
".",
"LOG",
".",
"debug",
"(",
"\"recover (flag = \"",
... | Obtains a list of prepared transaction branches from a resource manager.
@param _flag flag
@return always <code>null</code> | [
"Obtains",
"a",
"list",
"of",
"prepared",
"transaction",
"branches",
"from",
"a",
"resource",
"manager",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/store/VFSStoreResource.java#L560-L567 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.sendMessageWithAttachments | Observable<ChatResult> sendMessageWithAttachments(@NonNull final String conversationId, @NonNull final MessageToSend message, @Nullable final List<Attachment> attachments) {
final MessageProcessor messageProcessor = attCon.createMessageProcessor(message, attachments, conversationId, getProfileId());
return checkState()
.flatMap(client ->
{
messageProcessor.preparePreUpload(); // convert fom too large message parts to attachments, adds temp upload parts for all attachments
return upsertTempMessage(messageProcessor.createTempMessage()) // create temporary message
.flatMap(isOk -> attCon.uploadAttachments(messageProcessor.getAttachments(), client)) // upload attachments
.flatMap(uploaded -> {
if (uploaded != null && !uploaded.isEmpty()) {
messageProcessor.preparePostUpload(uploaded); // remove temp upload parts, add parts with upload data
return upsertTempMessage(messageProcessor.createTempMessage()); // update message with attachments details like url
} else {
return Observable.fromCallable(() -> true);
}
})
.flatMap(isOk -> client.service().messaging().sendMessage(conversationId, messageProcessor.prepareMessageToSend()) // send message with attachments details as additional message parts
.flatMap(result -> result.isSuccessful() ? updateStoreWithSentMsg(messageProcessor, result) : handleMessageError(messageProcessor, new ComapiException(result.getErrorBody()))) // update temporary message with a new message id obtained from the response
.onErrorResumeNext(t -> handleMessageError(messageProcessor, t))); // if error occurred update message status list adding error status
});
} | java | Observable<ChatResult> sendMessageWithAttachments(@NonNull final String conversationId, @NonNull final MessageToSend message, @Nullable final List<Attachment> attachments) {
final MessageProcessor messageProcessor = attCon.createMessageProcessor(message, attachments, conversationId, getProfileId());
return checkState()
.flatMap(client ->
{
messageProcessor.preparePreUpload(); // convert fom too large message parts to attachments, adds temp upload parts for all attachments
return upsertTempMessage(messageProcessor.createTempMessage()) // create temporary message
.flatMap(isOk -> attCon.uploadAttachments(messageProcessor.getAttachments(), client)) // upload attachments
.flatMap(uploaded -> {
if (uploaded != null && !uploaded.isEmpty()) {
messageProcessor.preparePostUpload(uploaded); // remove temp upload parts, add parts with upload data
return upsertTempMessage(messageProcessor.createTempMessage()); // update message with attachments details like url
} else {
return Observable.fromCallable(() -> true);
}
})
.flatMap(isOk -> client.service().messaging().sendMessage(conversationId, messageProcessor.prepareMessageToSend()) // send message with attachments details as additional message parts
.flatMap(result -> result.isSuccessful() ? updateStoreWithSentMsg(messageProcessor, result) : handleMessageError(messageProcessor, new ComapiException(result.getErrorBody()))) // update temporary message with a new message id obtained from the response
.onErrorResumeNext(t -> handleMessageError(messageProcessor, t))); // if error occurred update message status list adding error status
});
} | [
"Observable",
"<",
"ChatResult",
">",
"sendMessageWithAttachments",
"(",
"@",
"NonNull",
"final",
"String",
"conversationId",
",",
"@",
"NonNull",
"final",
"MessageToSend",
"message",
",",
"@",
"Nullable",
"final",
"List",
"<",
"Attachment",
">",
"attachments",
")... | Save and send message with attachments.
@param conversationId Unique conversation id.
@param message Message to send
@param attachments List of attachments to send with a message.
@return Observable with Chat SDK result. | [
"Save",
"and",
"send",
"message",
"with",
"attachments",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L172-L194 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleParticipantsAdded | public Observable<ChatResult> handleParticipantsAdded(final String conversationId) {
return persistenceController.getConversation(conversationId).flatMap(conversation -> {
if (conversation == null) {
return handleNoLocalConversation(conversationId);
} else {
return Observable.fromCallable(() -> new ChatResult(true, null));
}
});
} | java | public Observable<ChatResult> handleParticipantsAdded(final String conversationId) {
return persistenceController.getConversation(conversationId).flatMap(conversation -> {
if (conversation == null) {
return handleNoLocalConversation(conversationId);
} else {
return Observable.fromCallable(() -> new ChatResult(true, null));
}
});
} | [
"public",
"Observable",
"<",
"ChatResult",
">",
"handleParticipantsAdded",
"(",
"final",
"String",
"conversationId",
")",
"{",
"return",
"persistenceController",
".",
"getConversation",
"(",
"conversationId",
")",
".",
"flatMap",
"(",
"conversation",
"->",
"{",
"if"... | Handle participant added to a conversation Foundation SDK event.
@param conversationId Unique conversation id.
@return Observable with Chat SDK result. | [
"Handle",
"participant",
"added",
"to",
"a",
"conversation",
"Foundation",
"SDK",
"event",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L202-L210 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleMessageError | private Observable<ChatResult> handleMessageError(MessageProcessor mp, Throwable t) {
return persistenceController.updateStoreForSentError(mp.getConversationId(), mp.getTempId(), mp.getSender())
.map(success -> new ChatResult(false, new ChatResult.Error(0, t)));
} | java | private Observable<ChatResult> handleMessageError(MessageProcessor mp, Throwable t) {
return persistenceController.updateStoreForSentError(mp.getConversationId(), mp.getTempId(), mp.getSender())
.map(success -> new ChatResult(false, new ChatResult.Error(0, t)));
} | [
"private",
"Observable",
"<",
"ChatResult",
">",
"handleMessageError",
"(",
"MessageProcessor",
"mp",
",",
"Throwable",
"t",
")",
"{",
"return",
"persistenceController",
".",
"updateStoreForSentError",
"(",
"mp",
".",
"getConversationId",
"(",
")",
",",
"mp",
".",... | Handle failure when sent message.
@param mp Message processor holding message sent details.
@param t Thrown exception.
@return Observable with Chat SDK result. | [
"Handle",
"failure",
"when",
"sent",
"message",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L219-L222 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.checkState | Observable<RxComapiClient> checkState() {
final RxComapiClient client = clientReference.get();
if (client == null) {
return Observable.error(new ComapiException("No client instance available in controller."));
} else {
return Observable.fromCallable(() -> client);
}
} | java | Observable<RxComapiClient> checkState() {
final RxComapiClient client = clientReference.get();
if (client == null) {
return Observable.error(new ComapiException("No client instance available in controller."));
} else {
return Observable.fromCallable(() -> client);
}
} | [
"Observable",
"<",
"RxComapiClient",
">",
"checkState",
"(",
")",
"{",
"final",
"RxComapiClient",
"client",
"=",
"clientReference",
".",
"get",
"(",
")",
";",
"if",
"(",
"client",
"==",
"null",
")",
"{",
"return",
"Observable",
".",
"error",
"(",
"new",
... | Checks if controller state is correct.
@return Foundation client instance. | [
"Checks",
"if",
"controller",
"state",
"is",
"correct",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L229-L237 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleNoLocalConversation | Observable<ChatResult> handleNoLocalConversation(String conversationId) {
return checkState().flatMap(client -> client.service().messaging().getConversation(conversationId)
.flatMap(result -> {
if (result.isSuccessful() && result.getResult() != null) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build())
.map(success -> new ChatResult(success, success ? null : new ChatResult.Error(0, "External store reported failure.", "Error when inserting conversation "+conversationId)));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
}));
} | java | Observable<ChatResult> handleNoLocalConversation(String conversationId) {
return checkState().flatMap(client -> client.service().messaging().getConversation(conversationId)
.flatMap(result -> {
if (result.isSuccessful() && result.getResult() != null) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build())
.map(success -> new ChatResult(success, success ? null : new ChatResult.Error(0, "External store reported failure.", "Error when inserting conversation "+conversationId)));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
}));
} | [
"Observable",
"<",
"ChatResult",
">",
"handleNoLocalConversation",
"(",
"String",
"conversationId",
")",
"{",
"return",
"checkState",
"(",
")",
".",
"flatMap",
"(",
"client",
"->",
"client",
".",
"service",
"(",
")",
".",
"messaging",
"(",
")",
".",
"getConv... | When SDK detects missing conversation it makes query in services and saves in the saves locally.
@param conversationId Unique identifier of an conversation.
@return Observable to handle missing local conversation data. | [
"When",
"SDK",
"detects",
"missing",
"conversation",
"it",
"makes",
"query",
"in",
"services",
"and",
"saves",
"in",
"the",
"saves",
"locally",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L245-L256 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.markDelivered | Observable<ComapiResult<Void>> markDelivered(String conversationId, Set<String> ids) {
final List<MessageStatusUpdate> updates = new ArrayList<>();
updates.add(MessageStatusUpdate.builder().setMessagesIds(ids).setStatus(MessageStatus.delivered).setTimestamp(DateHelper.getCurrentUTC()).build());
return checkState().flatMap(client -> client.service().messaging().updateMessageStatus(conversationId, updates)
.retryWhen(observable -> {
return observable.zipWith(Observable.range(1, 3), (Func2<Throwable, Integer, Integer>) (throwable, integer) -> integer).flatMap(new Func1<Integer, Observable<Long>>() {
@Override
public Observable<Long> call(Integer retryCount) {
return Observable.timer((long) Math.pow(1, retryCount), TimeUnit.SECONDS);
}
});
}
));
} | java | Observable<ComapiResult<Void>> markDelivered(String conversationId, Set<String> ids) {
final List<MessageStatusUpdate> updates = new ArrayList<>();
updates.add(MessageStatusUpdate.builder().setMessagesIds(ids).setStatus(MessageStatus.delivered).setTimestamp(DateHelper.getCurrentUTC()).build());
return checkState().flatMap(client -> client.service().messaging().updateMessageStatus(conversationId, updates)
.retryWhen(observable -> {
return observable.zipWith(Observable.range(1, 3), (Func2<Throwable, Integer, Integer>) (throwable, integer) -> integer).flatMap(new Func1<Integer, Observable<Long>>() {
@Override
public Observable<Long> call(Integer retryCount) {
return Observable.timer((long) Math.pow(1, retryCount), TimeUnit.SECONDS);
}
});
}
));
} | [
"Observable",
"<",
"ComapiResult",
"<",
"Void",
">",
">",
"markDelivered",
"(",
"String",
"conversationId",
",",
"Set",
"<",
"String",
">",
"ids",
")",
"{",
"final",
"List",
"<",
"MessageStatusUpdate",
">",
"updates",
"=",
"new",
"ArrayList",
"<>",
"(",
")... | Mark messages in a conversations as delivered.
@param conversationId Conversation unique id.
@param ids Ids of messages in a single conversation to be marked as delivered. | [
"Mark",
"messages",
"in",
"a",
"conversations",
"as",
"delivered",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L264-L279 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.getProfileId | String getProfileId() {
final RxComapiClient client = clientReference.get();
return client != null ? client.getSession().getProfileId() : null;
} | java | String getProfileId() {
final RxComapiClient client = clientReference.get();
return client != null ? client.getSession().getProfileId() : null;
} | [
"String",
"getProfileId",
"(",
")",
"{",
"final",
"RxComapiClient",
"client",
"=",
"clientReference",
".",
"get",
"(",
")",
";",
"return",
"client",
"!=",
"null",
"?",
"client",
".",
"getSession",
"(",
")",
".",
"getProfileId",
"(",
")",
":",
"null",
";"... | Gets profile id from Foundation for the active user.
@return Active user profile id. | [
"Gets",
"profile",
"id",
"from",
"Foundation",
"for",
"the",
"active",
"user",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L322-L325 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.synchroniseStore | Observable<ChatResult> synchroniseStore() {
if (isSynchronising.getAndSet(true)) {
log.i("Synchronisation in progress.");
return Observable.fromCallable(() -> new ChatResult(true, null));
}
log.i("Synchronising store.");
return synchroniseConversations()
.onErrorReturn(t -> new ChatResult(false, new ChatResult.Error(0, t)))
.doOnNext(i -> {
if (i.isSuccessful()) {
log.i("Synchronisation successfully finished.");
} else {
log.e("Synchronisation finished with error. " + (i.getError() != null ? i.getError().getDetails() : ""));
}
isSynchronising.compareAndSet(true, false);
});
} | java | Observable<ChatResult> synchroniseStore() {
if (isSynchronising.getAndSet(true)) {
log.i("Synchronisation in progress.");
return Observable.fromCallable(() -> new ChatResult(true, null));
}
log.i("Synchronising store.");
return synchroniseConversations()
.onErrorReturn(t -> new ChatResult(false, new ChatResult.Error(0, t)))
.doOnNext(i -> {
if (i.isSuccessful()) {
log.i("Synchronisation successfully finished.");
} else {
log.e("Synchronisation finished with error. " + (i.getError() != null ? i.getError().getDetails() : ""));
}
isSynchronising.compareAndSet(true, false);
});
} | [
"Observable",
"<",
"ChatResult",
">",
"synchroniseStore",
"(",
")",
"{",
"if",
"(",
"isSynchronising",
".",
"getAndSet",
"(",
"true",
")",
")",
"{",
"log",
".",
"i",
"(",
"\"Synchronisation in progress.\"",
")",
";",
"return",
"Observable",
".",
"fromCallable"... | Check state for all conversations and update from services.
@return Result of synchronisation process. | [
"Check",
"state",
"for",
"all",
"conversations",
"and",
"update",
"from",
"services",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L332-L348 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleConversationCreated | Observable<ChatResult> handleConversationCreated(ComapiResult<ConversationDetails> result) {
if (result.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build()).map(success -> adapter.adaptResult(result, success));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
} | java | Observable<ChatResult> handleConversationCreated(ComapiResult<ConversationDetails> result) {
if (result.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build()).map(success -> adapter.adaptResult(result, success));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
} | [
"Observable",
"<",
"ChatResult",
">",
"handleConversationCreated",
"(",
"ComapiResult",
"<",
"ConversationDetails",
">",
"result",
")",
"{",
"if",
"(",
"result",
".",
"isSuccessful",
"(",
")",
")",
"{",
"return",
"persistenceController",
".",
"upsertConversation",
... | Handles conversation create service response.
@param result Service call response.
@return Observable emitting result of operations. | [
"Handles",
"conversation",
"create",
"service",
"response",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L356-L362 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleConversationDeleted | Observable<ChatResult> handleConversationDeleted(String conversationId, ComapiResult<Void> result) {
if (result.getCode() != ETAG_NOT_VALID) {
return persistenceController.deleteConversation(conversationId).map(success -> adapter.adaptResult(result, success));
} else {
return checkState().flatMap(client -> client.service().messaging().getConversation(conversationId)
.flatMap(newResult -> {
if (newResult.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(newResult.getResult(), newResult.getETag()).build())
.flatMap(success -> Observable.fromCallable(() -> new ChatResult(false, success ? new ChatResult.Error(ETAG_NOT_VALID, "Conversation updated, try delete again.", "Conversation "+conversationId+" updated in response to wrong eTag error when deleting.") : new ChatResult.Error(0, "Error updating custom store.", null))));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(newResult));
}
}));
}
} | java | Observable<ChatResult> handleConversationDeleted(String conversationId, ComapiResult<Void> result) {
if (result.getCode() != ETAG_NOT_VALID) {
return persistenceController.deleteConversation(conversationId).map(success -> adapter.adaptResult(result, success));
} else {
return checkState().flatMap(client -> client.service().messaging().getConversation(conversationId)
.flatMap(newResult -> {
if (newResult.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(newResult.getResult(), newResult.getETag()).build())
.flatMap(success -> Observable.fromCallable(() -> new ChatResult(false, success ? new ChatResult.Error(ETAG_NOT_VALID, "Conversation updated, try delete again.", "Conversation "+conversationId+" updated in response to wrong eTag error when deleting.") : new ChatResult.Error(0, "Error updating custom store.", null))));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(newResult));
}
}));
}
} | [
"Observable",
"<",
"ChatResult",
">",
"handleConversationDeleted",
"(",
"String",
"conversationId",
",",
"ComapiResult",
"<",
"Void",
">",
"result",
")",
"{",
"if",
"(",
"result",
".",
"getCode",
"(",
")",
"!=",
"ETAG_NOT_VALID",
")",
"{",
"return",
"persisten... | Handles conversation delete service response.
@param conversationId Unique identifier of an conversation.
@param result Service call response.
@return Observable emitting result of operations. | [
"Handles",
"conversation",
"delete",
"service",
"response",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L371-L385 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleConversationUpdated | Observable<ChatResult> handleConversationUpdated(ConversationUpdate request, ComapiResult<ConversationDetails> result) {
if (result.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build()).map(success -> adapter.adaptResult(result, success));
}
if (result.getCode() == ETAG_NOT_VALID) {
return checkState().flatMap(client -> client.service().messaging().getConversation(request.getId())
.flatMap(newResult -> {
if (newResult.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(newResult.getResult(), newResult.getETag()).build())
.flatMap(success -> Observable.fromCallable(() -> new ChatResult(false, success ? new ChatResult.Error(ETAG_NOT_VALID, "Conversation updated, try delete again.", "Conversation "+request.getId()+" updated in response to wrong eTag error when updating."): new ChatResult.Error(1500, "Error updating custom store.", null))));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(newResult));
}
}));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
} | java | Observable<ChatResult> handleConversationUpdated(ConversationUpdate request, ComapiResult<ConversationDetails> result) {
if (result.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(result.getResult(), result.getETag()).build()).map(success -> adapter.adaptResult(result, success));
}
if (result.getCode() == ETAG_NOT_VALID) {
return checkState().flatMap(client -> client.service().messaging().getConversation(request.getId())
.flatMap(newResult -> {
if (newResult.isSuccessful()) {
return persistenceController.upsertConversation(ChatConversation.builder().populate(newResult.getResult(), newResult.getETag()).build())
.flatMap(success -> Observable.fromCallable(() -> new ChatResult(false, success ? new ChatResult.Error(ETAG_NOT_VALID, "Conversation updated, try delete again.", "Conversation "+request.getId()+" updated in response to wrong eTag error when updating."): new ChatResult.Error(1500, "Error updating custom store.", null))));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(newResult));
}
}));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
} | [
"Observable",
"<",
"ChatResult",
">",
"handleConversationUpdated",
"(",
"ConversationUpdate",
"request",
",",
"ComapiResult",
"<",
"ConversationDetails",
">",
"result",
")",
"{",
"if",
"(",
"result",
".",
"isSuccessful",
"(",
")",
")",
"{",
"return",
"persistenceC... | Handles conversation update service response.
@param request Service API request object.
@param result Service call response.
@return Observable emitting result of operations. | [
"Handles",
"conversation",
"update",
"service",
"response",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L394-L416 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleMessageStatusToUpdate | Observable<ChatResult> handleMessageStatusToUpdate(String conversationId, List<MessageStatusUpdate> msgStatusList, ComapiResult<Void> result) {
if (result.isSuccessful() && msgStatusList != null && !msgStatusList.isEmpty()) {
return persistenceController.upsertMessageStatuses(conversationId, getProfileId(), msgStatusList).map(success -> adapter.adaptResult(result, success));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
} | java | Observable<ChatResult> handleMessageStatusToUpdate(String conversationId, List<MessageStatusUpdate> msgStatusList, ComapiResult<Void> result) {
if (result.isSuccessful() && msgStatusList != null && !msgStatusList.isEmpty()) {
return persistenceController.upsertMessageStatuses(conversationId, getProfileId(), msgStatusList).map(success -> adapter.adaptResult(result, success));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(result));
}
} | [
"Observable",
"<",
"ChatResult",
">",
"handleMessageStatusToUpdate",
"(",
"String",
"conversationId",
",",
"List",
"<",
"MessageStatusUpdate",
">",
"msgStatusList",
",",
"ComapiResult",
"<",
"Void",
">",
"result",
")",
"{",
"if",
"(",
"result",
".",
"isSuccessful"... | Handles message status update service response.
@param msgStatusList List of message status updates to process.
@param result Service call response.
@return Observable emitting result of operations. | [
"Handles",
"message",
"status",
"update",
"service",
"response",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L425-L431 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.upsertTempMessage | private Observable<Boolean> upsertTempMessage(ChatMessage message) {
return persistenceController.updateStoreWithNewMessage(message, noConversationListener)
.doOnError(t -> log.e("Error saving temp message " + t.getLocalizedMessage()))
.onErrorReturn(t -> false);
} | java | private Observable<Boolean> upsertTempMessage(ChatMessage message) {
return persistenceController.updateStoreWithNewMessage(message, noConversationListener)
.doOnError(t -> log.e("Error saving temp message " + t.getLocalizedMessage()))
.onErrorReturn(t -> false);
} | [
"private",
"Observable",
"<",
"Boolean",
">",
"upsertTempMessage",
"(",
"ChatMessage",
"message",
")",
"{",
"return",
"persistenceController",
".",
"updateStoreWithNewMessage",
"(",
"message",
",",
"noConversationListener",
")",
".",
"doOnError",
"(",
"t",
"->",
"lo... | Insert temporary message to the store for the ui to be responsive.
@param message Message to be send.
@return Observable emitting result of operations. | [
"Insert",
"temporary",
"message",
"to",
"the",
"store",
"for",
"the",
"ui",
"to",
"be",
"responsive",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L439-L443 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.updateStoreWithSentMsg | Observable<ChatResult> updateStoreWithSentMsg(MessageProcessor mp, ComapiResult<MessageSentResponse> response) {
if (response.isSuccessful()) {
return persistenceController.updateStoreWithNewMessage(mp.createFinalMessage(response.getResult()), noConversationListener).map(success -> adapter.adaptResult(response, success));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(response));
}
} | java | Observable<ChatResult> updateStoreWithSentMsg(MessageProcessor mp, ComapiResult<MessageSentResponse> response) {
if (response.isSuccessful()) {
return persistenceController.updateStoreWithNewMessage(mp.createFinalMessage(response.getResult()), noConversationListener).map(success -> adapter.adaptResult(response, success));
} else {
return Observable.fromCallable(() -> adapter.adaptResult(response));
}
} | [
"Observable",
"<",
"ChatResult",
">",
"updateStoreWithSentMsg",
"(",
"MessageProcessor",
"mp",
",",
"ComapiResult",
"<",
"MessageSentResponse",
">",
"response",
")",
"{",
"if",
"(",
"response",
".",
"isSuccessful",
"(",
")",
")",
"{",
"return",
"persistenceControl... | Handles message send service response. Will delete temporary message object. Same message but with correct message id will be inserted instead.
@param mp Message processor holding message sent details.
@param response Service call response.
@return Observable emitting result of operations. | [
"Handles",
"message",
"send",
"service",
"response",
".",
"Will",
"delete",
"temporary",
"message",
"object",
".",
"Same",
"message",
"but",
"with",
"correct",
"message",
"id",
"will",
"be",
"inserted",
"instead",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L452-L458 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.synchroniseConversations | private Observable<ChatResult> synchroniseConversations() {
return checkState().flatMap(client -> client.service().messaging()
.getConversations(false)
.flatMap(result -> persistenceController.loadAllConversations()
.map(chatConversationBases -> compare(result.isSuccessful(), result.getResult(), chatConversationBases)))
.flatMap(this::updateLocalConversationList)
.flatMap(result -> lookForMissingEvents(client, result))
.map(result -> new ChatResult(result.isSuccessful, null)));
} | java | private Observable<ChatResult> synchroniseConversations() {
return checkState().flatMap(client -> client.service().messaging()
.getConversations(false)
.flatMap(result -> persistenceController.loadAllConversations()
.map(chatConversationBases -> compare(result.isSuccessful(), result.getResult(), chatConversationBases)))
.flatMap(this::updateLocalConversationList)
.flatMap(result -> lookForMissingEvents(client, result))
.map(result -> new ChatResult(result.isSuccessful, null)));
} | [
"private",
"Observable",
"<",
"ChatResult",
">",
"synchroniseConversations",
"(",
")",
"{",
"return",
"checkState",
"(",
")",
".",
"flatMap",
"(",
"client",
"->",
"client",
".",
"service",
"(",
")",
".",
"messaging",
"(",
")",
".",
"getConversations",
"(",
... | Updates all conversation states.
@return Result of synchronisation with services. | [
"Updates",
"all",
"conversation",
"states",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L465-L474 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.compare | ConversationComparison compare(boolean successful, List<Conversation> remote, List<ChatConversationBase> local) {
return new ConversationComparison(successful, makeMapFromDownloadedConversations(remote), makeMapFromSavedConversations(local));
} | java | ConversationComparison compare(boolean successful, List<Conversation> remote, List<ChatConversationBase> local) {
return new ConversationComparison(successful, makeMapFromDownloadedConversations(remote), makeMapFromSavedConversations(local));
} | [
"ConversationComparison",
"compare",
"(",
"boolean",
"successful",
",",
"List",
"<",
"Conversation",
">",
"remote",
",",
"List",
"<",
"ChatConversationBase",
">",
"local",
")",
"{",
"return",
"new",
"ConversationComparison",
"(",
"successful",
",",
"makeMapFromDownl... | Compares remote and local conversation lists.
@param successful True if the service call was successful.
@param remote Conversation list obtained from the server.
@param local Conversation list obtained from local store.
@return Comparison object. | [
"Compares",
"remote",
"and",
"local",
"conversation",
"lists",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L484-L486 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.synchroniseConversation | Observable<ChatResult> synchroniseConversation(String conversationId) {
return checkState().flatMap(client -> client.service().messaging()
.queryMessages(conversationId, null, 1)
.map(result -> {
if (result.isSuccessful() && result.getResult() != null) {
return (long) result.getResult().getLatestEventId();
}
return -1L;
})
.flatMap(result -> persistenceController.getConversation(conversationId).map(loaded -> compare(result, loaded)))
.flatMap(this::updateLocalConversationList)
.flatMap(result -> lookForMissingEvents(client, result))
.map(result -> new ChatResult(result.isSuccessful, null)));
} | java | Observable<ChatResult> synchroniseConversation(String conversationId) {
return checkState().flatMap(client -> client.service().messaging()
.queryMessages(conversationId, null, 1)
.map(result -> {
if (result.isSuccessful() && result.getResult() != null) {
return (long) result.getResult().getLatestEventId();
}
return -1L;
})
.flatMap(result -> persistenceController.getConversation(conversationId).map(loaded -> compare(result, loaded)))
.flatMap(this::updateLocalConversationList)
.flatMap(result -> lookForMissingEvents(client, result))
.map(result -> new ChatResult(result.isSuccessful, null)));
} | [
"Observable",
"<",
"ChatResult",
">",
"synchroniseConversation",
"(",
"String",
"conversationId",
")",
"{",
"return",
"checkState",
"(",
")",
".",
"flatMap",
"(",
"client",
"->",
"client",
".",
"service",
"(",
")",
".",
"messaging",
"(",
")",
".",
"queryMess... | Updates single conversation state.
@return Result of synchronisation with services. | [
"Updates",
"single",
"conversation",
"state",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L504-L518 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.lookForMissingEvents | private Observable<ConversationComparison> lookForMissingEvents(final RxComapiClient client, ConversationComparison conversationComparison) {
if (!conversationComparison.isSuccessful || conversationComparison.conversationsToUpdate.isEmpty()) {
return Observable.fromCallable(() -> conversationComparison);
}
return synchroniseEvents(client, conversationComparison.conversationsToUpdate, new ArrayList<>())
.map(result -> {
if (conversationComparison.isSuccessful && !result) {
conversationComparison.addSuccess(false);
}
return conversationComparison;
});
} | java | private Observable<ConversationComparison> lookForMissingEvents(final RxComapiClient client, ConversationComparison conversationComparison) {
if (!conversationComparison.isSuccessful || conversationComparison.conversationsToUpdate.isEmpty()) {
return Observable.fromCallable(() -> conversationComparison);
}
return synchroniseEvents(client, conversationComparison.conversationsToUpdate, new ArrayList<>())
.map(result -> {
if (conversationComparison.isSuccessful && !result) {
conversationComparison.addSuccess(false);
}
return conversationComparison;
});
} | [
"private",
"Observable",
"<",
"ConversationComparison",
">",
"lookForMissingEvents",
"(",
"final",
"RxComapiClient",
"client",
",",
"ConversationComparison",
"conversationComparison",
")",
"{",
"if",
"(",
"!",
"conversationComparison",
".",
"isSuccessful",
"||",
"conversa... | Checks services for missing events in stored conversations.
@param client Foundation client.
@param conversationComparison Describes differences in local and remote conversation list.
@return Observable returning unchanged argument to further processing. | [
"Checks",
"services",
"for",
"missing",
"events",
"in",
"stored",
"conversations",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L527-L540 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.updateLocalConversationList | private Observable<ConversationComparison> updateLocalConversationList(final ConversationComparison conversationComparison) {
return Observable.zip(persistenceController.deleteConversations(conversationComparison.conversationsToDelete),
persistenceController.upsertConversations(conversationComparison.conversationsToAdd),
persistenceController.updateConversations(conversationComparison.conversationsToUpdate),
(success1, success2, success3) -> success1 && success2 && success3)
.map(result -> {
conversationComparison.addSuccess(result);
return conversationComparison;
});
} | java | private Observable<ConversationComparison> updateLocalConversationList(final ConversationComparison conversationComparison) {
return Observable.zip(persistenceController.deleteConversations(conversationComparison.conversationsToDelete),
persistenceController.upsertConversations(conversationComparison.conversationsToAdd),
persistenceController.updateConversations(conversationComparison.conversationsToUpdate),
(success1, success2, success3) -> success1 && success2 && success3)
.map(result -> {
conversationComparison.addSuccess(result);
return conversationComparison;
});
} | [
"private",
"Observable",
"<",
"ConversationComparison",
">",
"updateLocalConversationList",
"(",
"final",
"ConversationComparison",
"conversationComparison",
")",
"{",
"return",
"Observable",
".",
"zip",
"(",
"persistenceController",
".",
"deleteConversations",
"(",
"conver... | Update list of local conversations.
@param conversationComparison Describes differences in local and remote participant list.
@return Observable returning unchanged argument to further processing. | [
"Update",
"list",
"of",
"local",
"conversations",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L548-L558 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.synchroniseEvents | private Observable<Boolean> synchroniseEvents(final RxComapiClient client, @NonNull final List<ChatConversation> conversationsToUpdate, @NonNull final List<Boolean> successes) {
final List<ChatConversation> limited = limitNumberOfConversations(conversationsToUpdate);
if (limited.isEmpty()) {
return Observable.fromCallable(() -> true);
}
return Observable.from(limited)
.onBackpressureBuffer()
.flatMap(conversation -> persistenceController.getConversation(conversation.getConversationId()))
.flatMap(conversation -> {
if (conversation.getLastRemoteEventId() > conversation.getLastLocalEventId()) {
final long from = conversation.getLastLocalEventId() >= 0 ? conversation.getLastLocalEventId() : 0;
return queryEventsRecursively(client, conversation.getConversationId(), from, 0, successes).map(ComapiResult::isSuccessful);
} else {
return Observable.fromCallable((Callable<Object>) () -> true);
}
})
.flatMap(res -> Observable.from(successes).all(Boolean::booleanValue));
} | java | private Observable<Boolean> synchroniseEvents(final RxComapiClient client, @NonNull final List<ChatConversation> conversationsToUpdate, @NonNull final List<Boolean> successes) {
final List<ChatConversation> limited = limitNumberOfConversations(conversationsToUpdate);
if (limited.isEmpty()) {
return Observable.fromCallable(() -> true);
}
return Observable.from(limited)
.onBackpressureBuffer()
.flatMap(conversation -> persistenceController.getConversation(conversation.getConversationId()))
.flatMap(conversation -> {
if (conversation.getLastRemoteEventId() > conversation.getLastLocalEventId()) {
final long from = conversation.getLastLocalEventId() >= 0 ? conversation.getLastLocalEventId() : 0;
return queryEventsRecursively(client, conversation.getConversationId(), from, 0, successes).map(ComapiResult::isSuccessful);
} else {
return Observable.fromCallable((Callable<Object>) () -> true);
}
})
.flatMap(res -> Observable.from(successes).all(Boolean::booleanValue));
} | [
"private",
"Observable",
"<",
"Boolean",
">",
"synchroniseEvents",
"(",
"final",
"RxComapiClient",
"client",
",",
"@",
"NonNull",
"final",
"List",
"<",
"ChatConversation",
">",
"conversationsToUpdate",
",",
"@",
"NonNull",
"final",
"List",
"<",
"Boolean",
">",
"... | Synchronise missing events for the list of locally stored conversations.
@param client Foundation client.
@param conversationsToUpdate List of conversations to query last events.
@param successes List of partial successes.
@return Observable with the merged result of operations. | [
"Synchronise",
"missing",
"events",
"for",
"the",
"list",
"of",
"locally",
"stored",
"conversations",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L568-L588 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.queryEventsRecursively | private Observable<ComapiResult<ConversationEventsResponse>> queryEventsRecursively(final RxComapiClient client, final String conversationId, final long lastEventId, final int count, final List<Boolean> successes) {
return client.service().messaging().queryConversationEvents(conversationId, lastEventId, eventsPerQuery)
.flatMap(result -> processEventsQueryResponse(result, successes))
.flatMap(result -> {
if (result.getResult() != null && result.getResult().getEventsInOrder().size() >= eventsPerQuery && count < maxEventQueries) {
return queryEventsRecursively(client, conversationId, lastEventId + result.getResult().getEventsInOrder().size(), count + 1, successes);
} else {
return Observable.just(result);
}
});
} | java | private Observable<ComapiResult<ConversationEventsResponse>> queryEventsRecursively(final RxComapiClient client, final String conversationId, final long lastEventId, final int count, final List<Boolean> successes) {
return client.service().messaging().queryConversationEvents(conversationId, lastEventId, eventsPerQuery)
.flatMap(result -> processEventsQueryResponse(result, successes))
.flatMap(result -> {
if (result.getResult() != null && result.getResult().getEventsInOrder().size() >= eventsPerQuery && count < maxEventQueries) {
return queryEventsRecursively(client, conversationId, lastEventId + result.getResult().getEventsInOrder().size(), count + 1, successes);
} else {
return Observable.just(result);
}
});
} | [
"private",
"Observable",
"<",
"ComapiResult",
"<",
"ConversationEventsResponse",
">",
">",
"queryEventsRecursively",
"(",
"final",
"RxComapiClient",
"client",
",",
"final",
"String",
"conversationId",
",",
"final",
"long",
"lastEventId",
",",
"final",
"int",
"count",
... | Synchronise missing events for particular conversation.
@param client Foundation client.
@param conversationId Unique ID of a conversation.
@param lastEventId Last known event id - query should start form it.
@param count Number of queries already made.
@param successes list of query & processing results in recursive call.
@return Observable with the merged result of operations. | [
"Synchronise",
"missing",
"events",
"for",
"particular",
"conversation",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L600-L611 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.processEventsQueryResponse | private Observable<ComapiResult<ConversationEventsResponse>> processEventsQueryResponse(ComapiResult<ConversationEventsResponse> result, final List<Boolean> successes) {
ConversationEventsResponse response = result.getResult();
successes.add(result.isSuccessful());
if (response != null && response.getEventsInOrder().size() > 0) {
Collection<Event> events = response.getEventsInOrder();
List<Observable<Boolean>> list = new ArrayList<>();
for (Event event : events) {
if (event instanceof MessageSentEvent) {
MessageSentEvent messageEvent = (MessageSentEvent) event;
list.add(persistenceController.updateStoreWithNewMessage(ChatMessage.builder().populate(messageEvent).build(), noConversationListener));
} else if (event instanceof MessageDeliveredEvent) {
list.add(persistenceController.upsertMessageStatus(ChatMessageStatus.builder().populate((MessageDeliveredEvent) event).build()));
} else if (event instanceof MessageReadEvent) {
list.add(persistenceController.upsertMessageStatus(ChatMessageStatus.builder().populate((MessageReadEvent) event).build()));
}
}
return Observable.from(list)
.flatMap(task -> task)
.doOnNext(successes::add)
.toList()
.map(results -> result);
}
return Observable.fromCallable(() -> result);
} | java | private Observable<ComapiResult<ConversationEventsResponse>> processEventsQueryResponse(ComapiResult<ConversationEventsResponse> result, final List<Boolean> successes) {
ConversationEventsResponse response = result.getResult();
successes.add(result.isSuccessful());
if (response != null && response.getEventsInOrder().size() > 0) {
Collection<Event> events = response.getEventsInOrder();
List<Observable<Boolean>> list = new ArrayList<>();
for (Event event : events) {
if (event instanceof MessageSentEvent) {
MessageSentEvent messageEvent = (MessageSentEvent) event;
list.add(persistenceController.updateStoreWithNewMessage(ChatMessage.builder().populate(messageEvent).build(), noConversationListener));
} else if (event instanceof MessageDeliveredEvent) {
list.add(persistenceController.upsertMessageStatus(ChatMessageStatus.builder().populate((MessageDeliveredEvent) event).build()));
} else if (event instanceof MessageReadEvent) {
list.add(persistenceController.upsertMessageStatus(ChatMessageStatus.builder().populate((MessageReadEvent) event).build()));
}
}
return Observable.from(list)
.flatMap(task -> task)
.doOnNext(successes::add)
.toList()
.map(results -> result);
}
return Observable.fromCallable(() -> result);
} | [
"private",
"Observable",
"<",
"ComapiResult",
"<",
"ConversationEventsResponse",
">",
">",
"processEventsQueryResponse",
"(",
"ComapiResult",
"<",
"ConversationEventsResponse",
">",
"result",
",",
"final",
"List",
"<",
"Boolean",
">",
"successes",
")",
"{",
"Conversat... | Process the event query response. Calls appropraiate persistance controller methods for received events.
@param result Event query response.
@param successes List of successes in recursive query.
@return Observable with same result object for further processing. | [
"Process",
"the",
"event",
"query",
"response",
".",
"Calls",
"appropraiate",
"persistance",
"controller",
"methods",
"for",
"received",
"events",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L620-L650 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.limitNumberOfConversations | private List<ChatConversation> limitNumberOfConversations(List<ChatConversation> conversations) {
List<ChatConversation> noEmptyConversations = new ArrayList<>();
for (ChatConversation c : conversations) {
if (c.getLastRemoteEventId() != null && c.getLastRemoteEventId() >= 0) {
noEmptyConversations.add(c);
}
}
List<ChatConversation> limitedList;
if (noEmptyConversations.size() <= maxConversationsSynced) {
limitedList = noEmptyConversations;
} else {
SortedMap<Long, ChatConversation> sorted = new TreeMap<>();
for (ChatConversation conversation : noEmptyConversations) {
Long updatedOn = conversation.getUpdatedOn();
if (updatedOn != null) {
sorted.put(updatedOn, conversation);
}
}
limitedList = new ArrayList<>();
Object[] array = sorted.values().toArray();
for (int i = 0; i < Math.min(maxConversationsSynced, array.length); i++) {
limitedList.add((ChatConversation) array[i]);
}
}
return limitedList;
} | java | private List<ChatConversation> limitNumberOfConversations(List<ChatConversation> conversations) {
List<ChatConversation> noEmptyConversations = new ArrayList<>();
for (ChatConversation c : conversations) {
if (c.getLastRemoteEventId() != null && c.getLastRemoteEventId() >= 0) {
noEmptyConversations.add(c);
}
}
List<ChatConversation> limitedList;
if (noEmptyConversations.size() <= maxConversationsSynced) {
limitedList = noEmptyConversations;
} else {
SortedMap<Long, ChatConversation> sorted = new TreeMap<>();
for (ChatConversation conversation : noEmptyConversations) {
Long updatedOn = conversation.getUpdatedOn();
if (updatedOn != null) {
sorted.put(updatedOn, conversation);
}
}
limitedList = new ArrayList<>();
Object[] array = sorted.values().toArray();
for (int i = 0; i < Math.min(maxConversationsSynced, array.length); i++) {
limitedList.add((ChatConversation) array[i]);
}
}
return limitedList;
} | [
"private",
"List",
"<",
"ChatConversation",
">",
"limitNumberOfConversations",
"(",
"List",
"<",
"ChatConversation",
">",
"conversations",
")",
"{",
"List",
"<",
"ChatConversation",
">",
"noEmptyConversations",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
... | Limits number of conversations to check and synchronise. Emty conversations wont be synchronised. The synchronisation will take place for twenty conversations updated most recently.
@param conversations List of conversations to be limited.
@return Limited list of conversations to update. | [
"Limits",
"number",
"of",
"conversations",
"to",
"check",
"and",
"synchronise",
".",
"Emty",
"conversations",
"wont",
"be",
"synchronised",
".",
"The",
"synchronisation",
"will",
"take",
"place",
"for",
"twenty",
"conversations",
"updated",
"most",
"recently",
"."... | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L658-L687 | train |
comapi/comapi-chat-sdk-android | COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java | ChatController.handleMessage | public Observable<Boolean> handleMessage(final ChatMessage message) {
String sender = message.getSentBy();
Observable<Boolean> replaceMessages = persistenceController.updateStoreWithNewMessage(message, noConversationListener);
if (!TextUtils.isEmpty(sender) && !sender.equals(getProfileId())) {
final Set<String> ids = new HashSet<>();
ids.add(message.getMessageId());
return Observable.zip(replaceMessages, markDelivered(message.getConversationId(), ids), (saved, result) -> saved && result.isSuccessful());
} else {
return replaceMessages;
}
} | java | public Observable<Boolean> handleMessage(final ChatMessage message) {
String sender = message.getSentBy();
Observable<Boolean> replaceMessages = persistenceController.updateStoreWithNewMessage(message, noConversationListener);
if (!TextUtils.isEmpty(sender) && !sender.equals(getProfileId())) {
final Set<String> ids = new HashSet<>();
ids.add(message.getMessageId());
return Observable.zip(replaceMessages, markDelivered(message.getConversationId(), ids), (saved, result) -> saved && result.isSuccessful());
} else {
return replaceMessages;
}
} | [
"public",
"Observable",
"<",
"Boolean",
">",
"handleMessage",
"(",
"final",
"ChatMessage",
"message",
")",
"{",
"String",
"sender",
"=",
"message",
".",
"getSentBy",
"(",
")",
";",
"Observable",
"<",
"Boolean",
">",
"replaceMessages",
"=",
"persistenceController... | Handle incomming message. Replace temporary message with received one and mark as delivered.
@param message Message to save and mark delivered.
@return Observable with a result. | [
"Handle",
"incomming",
"message",
".",
"Replace",
"temporary",
"message",
"with",
"received",
"one",
"and",
"mark",
"as",
"delivered",
"."
] | 388f37bfacb7793ce30c92ab70e5f32848bbe460 | https://github.com/comapi/comapi-chat-sdk-android/blob/388f37bfacb7793ce30c92ab70e5f32848bbe460/COMAPI/chat/src/main/java/com/comapi/chat/ChatController.java#L695-L712 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/grammar/state/NFA.java | NFA.analyzeEndStop | public void analyzeEndStop()
{
DFA<T> dfa = constructDFA(new Scope<DFAState<T>>("analyzeEndStop"));
for (DFAState<T> s : dfa)
{
if (s.isAccepting())
{
if (s.isEndStop())
{
for (NFAState<T> n : s.getNfaSet())
{
if (n.isAccepting())
{
n.setEndStop(true);
}
}
}
}
}
} | java | public void analyzeEndStop()
{
DFA<T> dfa = constructDFA(new Scope<DFAState<T>>("analyzeEndStop"));
for (DFAState<T> s : dfa)
{
if (s.isAccepting())
{
if (s.isEndStop())
{
for (NFAState<T> n : s.getNfaSet())
{
if (n.isAccepting())
{
n.setEndStop(true);
}
}
}
}
}
} | [
"public",
"void",
"analyzeEndStop",
"(",
")",
"{",
"DFA",
"<",
"T",
">",
"dfa",
"=",
"constructDFA",
"(",
"new",
"Scope",
"<",
"DFAState",
"<",
"T",
">",
">",
"(",
"\"analyzeEndStop\"",
")",
")",
";",
"for",
"(",
"DFAState",
"<",
"T",
">",
"s",
":"... | Marks all nfa states that can be accepting to end stop. | [
"Marks",
"all",
"nfa",
"states",
"that",
"can",
"be",
"accepting",
"to",
"end",
"stop",
"."
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/grammar/state/NFA.java#L147-L166 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/grammar/state/NFA.java | NFA.constructDFA | public DFA<T> constructDFA(Scope<DFAState<T>> scope)
{
return new DFA<>(first.constructDFA(scope), scope.count());
} | java | public DFA<T> constructDFA(Scope<DFAState<T>> scope)
{
return new DFA<>(first.constructDFA(scope), scope.count());
} | [
"public",
"DFA",
"<",
"T",
">",
"constructDFA",
"(",
"Scope",
"<",
"DFAState",
"<",
"T",
">",
">",
"scope",
")",
"{",
"return",
"new",
"DFA",
"<>",
"(",
"first",
".",
"constructDFA",
"(",
"scope",
")",
",",
"scope",
".",
"count",
"(",
")",
")",
"... | Constructs a dfa from using first nfa state as starting state.
@param scope
@return | [
"Constructs",
"a",
"dfa",
"from",
"using",
"first",
"nfa",
"state",
"as",
"starting",
"state",
"."
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/grammar/state/NFA.java#L172-L175 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/grammar/state/NFA.java | NFA.concat | public void concat(NFA<T> nfa)
{
last.addEpsilon(nfa.getFirst());
last = nfa.last;
} | java | public void concat(NFA<T> nfa)
{
last.addEpsilon(nfa.getFirst());
last = nfa.last;
} | [
"public",
"void",
"concat",
"(",
"NFA",
"<",
"T",
">",
"nfa",
")",
"{",
"last",
".",
"addEpsilon",
"(",
"nfa",
".",
"getFirst",
"(",
")",
")",
";",
"last",
"=",
"nfa",
".",
"last",
";",
"}"
] | Concatenates this to nfa by making epsilon move from this last to nfa first.
@param nfa | [
"Concatenates",
"this",
"to",
"nfa",
"by",
"making",
"epsilon",
"move",
"from",
"this",
"last",
"to",
"nfa",
"first",
"."
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/grammar/state/NFA.java#L180-L184 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/update/version/Application.java | Application.getApplicationFromSource | public static Application getApplicationFromSource(final File _versionFile,
final List<String> _classpathElements,
final File _eFapsDir,
final File _outputDir,
final List<String> _includes,
final List<String> _excludes,
final Map<String, String> _file2typeMapping)
throws InstallationException
{
final Map<String, String> file2typeMapping = _file2typeMapping == null
? Application.DEFAULT_TYPE_MAPPING
: _file2typeMapping;
final Application appl;
try {
appl = Application.getApplication(_versionFile.toURI().toURL(),
_eFapsDir.toURI().toURL(),
_classpathElements);
for (final String fileName : Application.getFiles(_eFapsDir, _includes, _excludes)) {
final String type = file2typeMapping.get(fileName.substring(fileName.lastIndexOf(".") + 1));
appl.install.addFile(new InstallFile().setType(type).setURL(
new File(_eFapsDir, fileName).toURI().toURL()));
}
if (_outputDir.exists()) {
for (final String fileName : Application.getFiles(_outputDir, _includes, _excludes)) {
final String type = file2typeMapping.get(fileName.substring(fileName.lastIndexOf(".") + 1));
appl.install.addFile(new InstallFile().setType(type).setURL(
new File(_outputDir, fileName).toURI().toURL()));
}
}
} catch (final IOException e) {
throw new InstallationException("Could not open / read version file " + "'" + _versionFile + "'", e);
// CHECKSTYLE:OFF
} catch (final Exception e) {
// CHECKSTYLE:ON
throw new InstallationException("Read version file '" + _versionFile + "' failed", e);
}
return appl;
} | java | public static Application getApplicationFromSource(final File _versionFile,
final List<String> _classpathElements,
final File _eFapsDir,
final File _outputDir,
final List<String> _includes,
final List<String> _excludes,
final Map<String, String> _file2typeMapping)
throws InstallationException
{
final Map<String, String> file2typeMapping = _file2typeMapping == null
? Application.DEFAULT_TYPE_MAPPING
: _file2typeMapping;
final Application appl;
try {
appl = Application.getApplication(_versionFile.toURI().toURL(),
_eFapsDir.toURI().toURL(),
_classpathElements);
for (final String fileName : Application.getFiles(_eFapsDir, _includes, _excludes)) {
final String type = file2typeMapping.get(fileName.substring(fileName.lastIndexOf(".") + 1));
appl.install.addFile(new InstallFile().setType(type).setURL(
new File(_eFapsDir, fileName).toURI().toURL()));
}
if (_outputDir.exists()) {
for (final String fileName : Application.getFiles(_outputDir, _includes, _excludes)) {
final String type = file2typeMapping.get(fileName.substring(fileName.lastIndexOf(".") + 1));
appl.install.addFile(new InstallFile().setType(type).setURL(
new File(_outputDir, fileName).toURI().toURL()));
}
}
} catch (final IOException e) {
throw new InstallationException("Could not open / read version file " + "'" + _versionFile + "'", e);
// CHECKSTYLE:OFF
} catch (final Exception e) {
// CHECKSTYLE:ON
throw new InstallationException("Read version file '" + _versionFile + "' failed", e);
}
return appl;
} | [
"public",
"static",
"Application",
"getApplicationFromSource",
"(",
"final",
"File",
"_versionFile",
",",
"final",
"List",
"<",
"String",
">",
"_classpathElements",
",",
"final",
"File",
"_eFapsDir",
",",
"final",
"File",
"_outputDir",
",",
"final",
"List",
"<",
... | Returns the application definition read from a source directory.
@param _versionFile version file which defines the application
@param _classpathElements class path elements (required to compile)
@param _eFapsDir root directory with the XML installation
files
@param _outputDir directory used as target for generated code
@param _includes list of includes; if <code>null</code>
{@link #DEFAULT_INCLUDES} are used
@param _excludes list of excludes; if <code>null</code>
{@link #DEFAULT_EXCLUDES} are used
@param _file2typeMapping mapping of file extension to type; if
<code>null</code> {@link #DEFAULT_TYPE_MAPPING} is used
@return application instance with all version information
@throws InstallationException if version file could not be read or opened | [
"Returns",
"the",
"application",
"definition",
"read",
"from",
"a",
"source",
"directory",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/update/version/Application.java#L285-L323 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/update/version/Application.java | Application.getApplicationFromClassPath | public static Application getApplicationFromClassPath(final String _application,
final List<String> _classpath)
throws InstallationException
{
return Application.getApplicationsFromClassPath(_application, _classpath).get(_application);
} | java | public static Application getApplicationFromClassPath(final String _application,
final List<String> _classpath)
throws InstallationException
{
return Application.getApplicationsFromClassPath(_application, _classpath).get(_application);
} | [
"public",
"static",
"Application",
"getApplicationFromClassPath",
"(",
"final",
"String",
"_application",
",",
"final",
"List",
"<",
"String",
">",
"_classpath",
")",
"throws",
"InstallationException",
"{",
"return",
"Application",
".",
"getApplicationsFromClassPath",
"... | Method to get the applications from the class path.
@param _application searched application in the class path
@param _classpath class path (list of the complete class path)
@return List of applications
@throws InstallationException if the install.xml file in the class path
could not be accessed | [
"Method",
"to",
"get",
"the",
"applications",
"from",
"the",
"class",
"path",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/update/version/Application.java#L368-L373 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/update/version/Application.java | Application.getApplicationsFromClassPath | public static Map<String, Application> getApplicationsFromClassPath(final String _application,
final List<String> _classpath)
throws InstallationException
{
final Map<String, Application> appls = new HashMap<>();
try {
final ClassLoader parent = Application.class.getClassLoader();
final List<URL> urls = new ArrayList<>();
for (final String pathElement : _classpath) {
urls.add(new File(pathElement).toURI().toURL());
}
final URLClassLoader cl = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), parent);
// get install application (read from all install xml files)
final Enumeration<URL> urlEnum = cl.getResources("META-INF/efaps/install.xml");
while (urlEnum.hasMoreElements()) {
// TODO: why class path?
final URL url = urlEnum.nextElement();
final Application appl = Application.getApplication(url, new URL(url, "../../../"), _classpath);
appls.put(appl.getApplication(), appl);
}
} catch (final IOException e) {
throw new InstallationException("Could not access the install.xml file "
+ "(in path META-INF/efaps/ path of each eFaps install jar).", e);
}
return appls;
} | java | public static Map<String, Application> getApplicationsFromClassPath(final String _application,
final List<String> _classpath)
throws InstallationException
{
final Map<String, Application> appls = new HashMap<>();
try {
final ClassLoader parent = Application.class.getClassLoader();
final List<URL> urls = new ArrayList<>();
for (final String pathElement : _classpath) {
urls.add(new File(pathElement).toURI().toURL());
}
final URLClassLoader cl = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), parent);
// get install application (read from all install xml files)
final Enumeration<URL> urlEnum = cl.getResources("META-INF/efaps/install.xml");
while (urlEnum.hasMoreElements()) {
// TODO: why class path?
final URL url = urlEnum.nextElement();
final Application appl = Application.getApplication(url, new URL(url, "../../../"), _classpath);
appls.put(appl.getApplication(), appl);
}
} catch (final IOException e) {
throw new InstallationException("Could not access the install.xml file "
+ "(in path META-INF/efaps/ path of each eFaps install jar).", e);
}
return appls;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"Application",
">",
"getApplicationsFromClassPath",
"(",
"final",
"String",
"_application",
",",
"final",
"List",
"<",
"String",
">",
"_classpath",
")",
"throws",
"InstallationException",
"{",
"final",
"Map",
"<",
"... | Method to get all applications from the class path.
@param _application searched application in the class path
@param _classpath class path (list of the complete class path)
@return List of applications
@throws InstallationException if the install.xml file in the class path
could not be accessed | [
"Method",
"to",
"get",
"all",
"applications",
"from",
"the",
"class",
"path",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/update/version/Application.java#L385-L410 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/update/version/Application.java | Application.updateLastVersion | public void updateLastVersion(final String _userName,
final String _password,
final Set<Profile> _profiles)
throws Exception
{
// reload cache (if possible)
reloadCache();
// load installed versions
Context.begin();
EFapsClassLoader.getOfflineInstance(getClass().getClassLoader());
final Map<String, Integer> latestVersions = this.install.getLatestVersions();
Context.rollback();
final long latestVersion = latestVersions.get(this.application);
final ApplicationVersion version = getLastVersion();
if (version.getNumber() == latestVersion) {
Application.LOG.info("Update version '{}' of application '{}' ", version.getNumber(), this.application);
version.install(this.install, version.getNumber(), _profiles, _userName, _password);
Application.LOG.info("Finished update of version '{}'", version.getNumber());
} else {
Application.LOG.error("Version {}' of application '{}' not installed and could not updated!",
version.getNumber(), this.application);
}
} | java | public void updateLastVersion(final String _userName,
final String _password,
final Set<Profile> _profiles)
throws Exception
{
// reload cache (if possible)
reloadCache();
// load installed versions
Context.begin();
EFapsClassLoader.getOfflineInstance(getClass().getClassLoader());
final Map<String, Integer> latestVersions = this.install.getLatestVersions();
Context.rollback();
final long latestVersion = latestVersions.get(this.application);
final ApplicationVersion version = getLastVersion();
if (version.getNumber() == latestVersion) {
Application.LOG.info("Update version '{}' of application '{}' ", version.getNumber(), this.application);
version.install(this.install, version.getNumber(), _profiles, _userName, _password);
Application.LOG.info("Finished update of version '{}'", version.getNumber());
} else {
Application.LOG.error("Version {}' of application '{}' not installed and could not updated!",
version.getNumber(), this.application);
}
} | [
"public",
"void",
"updateLastVersion",
"(",
"final",
"String",
"_userName",
",",
"final",
"String",
"_password",
",",
"final",
"Set",
"<",
"Profile",
">",
"_profiles",
")",
"throws",
"Exception",
"{",
"// reload cache (if possible)",
"reloadCache",
"(",
")",
";",
... | Updates the last installed version.
@param _userName name of logged in user
@param _password password of logged in user
@param _profiles Profiles to be applied
@throws Exception on error | [
"Updates",
"the",
"last",
"installed",
"version",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/update/version/Application.java#L617-L643 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/update/version/Application.java | Application.reloadCache | protected void reloadCache()
throws InstallationException
{
try {
LOG.info("Reloading Cache");
Context.begin();
if (RunLevel.isInitialisable()) {
RunLevel.init("shell");
RunLevel.execute();
}
Context.commit();
} catch (final EFapsException e) {
throw new InstallationException("Reload cache failed", e);
}
} | java | protected void reloadCache()
throws InstallationException
{
try {
LOG.info("Reloading Cache");
Context.begin();
if (RunLevel.isInitialisable()) {
RunLevel.init("shell");
RunLevel.execute();
}
Context.commit();
} catch (final EFapsException e) {
throw new InstallationException("Reload cache failed", e);
}
} | [
"protected",
"void",
"reloadCache",
"(",
")",
"throws",
"InstallationException",
"{",
"try",
"{",
"LOG",
".",
"info",
"(",
"\"Reloading Cache\"",
")",
";",
"Context",
".",
"begin",
"(",
")",
";",
"if",
"(",
"RunLevel",
".",
"isInitialisable",
"(",
")",
")"... | Reloads the eFaps cache.
@throws InstallationException if reload of the cache failed | [
"Reloads",
"the",
"eFaps",
"cache",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/update/version/Application.java#L743-L757 | train |
tvesalainen/lpg | src/main/java/org/vesalainen/parser/util/CharInput.java | CharInput.getString | @Override
public String getString(long start, int length)
{
if (length == 0)
{
return "";
}
if (array != null)
{
int ps = (int) (start % size);
int es = (int) ((start+length) % size);
if (ps < es)
{
return new String(array, ps, length);
}
else
{
StringBuilder sb = new StringBuilder();
sb.append(array, ps, size-ps);
sb.append(array, 0, es);
return sb.toString();
}
}
else
{
StringBuilder sb = new StringBuilder();
for (int ii=0;ii<length;ii++)
{
sb.append((char)get(start+ii));
}
return sb.toString();
}
} | java | @Override
public String getString(long start, int length)
{
if (length == 0)
{
return "";
}
if (array != null)
{
int ps = (int) (start % size);
int es = (int) ((start+length) % size);
if (ps < es)
{
return new String(array, ps, length);
}
else
{
StringBuilder sb = new StringBuilder();
sb.append(array, ps, size-ps);
sb.append(array, 0, es);
return sb.toString();
}
}
else
{
StringBuilder sb = new StringBuilder();
for (int ii=0;ii<length;ii++)
{
sb.append((char)get(start+ii));
}
return sb.toString();
}
} | [
"@",
"Override",
"public",
"String",
"getString",
"(",
"long",
"start",
",",
"int",
"length",
")",
"{",
"if",
"(",
"length",
"==",
"0",
")",
"{",
"return",
"\"\"",
";",
"}",
"if",
"(",
"array",
"!=",
"null",
")",
"{",
"int",
"ps",
"=",
"(",
"int"... | Returns string from buffer
@param start Start of input
@param length Length of input
@return | [
"Returns",
"string",
"from",
"buffer"
] | 0917b8d295e9772b9f8a0affc258a08530cd567a | https://github.com/tvesalainen/lpg/blob/0917b8d295e9772b9f8a0affc258a08530cd567a/src/main/java/org/vesalainen/parser/util/CharInput.java#L154-L186 | train |
gravityrd/jsondto | src/main/java/com/gravityrd/receng/web/webshop/jsondto/GravityNameValue.java | GravityNameValue.groupNameToSet | static Map<String, Set<String>> groupNameToSet(GravityNameValue[] nameValues) {
Map<String, Set<String>> result = new HashMap<>();
for (GravityNameValue nameValue : nameValues) {
if (nameValue.name == null || nameValue.value == null) continue;
if (!result.containsKey(nameValue.name)) result.put(nameValue.name, new LinkedHashSet<String>());
Collections.addAll(result.get(nameValue.name), nameValue.value);
}
return result;
} | java | static Map<String, Set<String>> groupNameToSet(GravityNameValue[] nameValues) {
Map<String, Set<String>> result = new HashMap<>();
for (GravityNameValue nameValue : nameValues) {
if (nameValue.name == null || nameValue.value == null) continue;
if (!result.containsKey(nameValue.name)) result.put(nameValue.name, new LinkedHashSet<String>());
Collections.addAll(result.get(nameValue.name), nameValue.value);
}
return result;
} | [
"static",
"Map",
"<",
"String",
",",
"Set",
"<",
"String",
">",
">",
"groupNameToSet",
"(",
"GravityNameValue",
"[",
"]",
"nameValues",
")",
"{",
"Map",
"<",
"String",
",",
"Set",
"<",
"String",
">",
">",
"result",
"=",
"new",
"HashMap",
"<>",
"(",
"... | Transform grouped into a map of name to a linked set of values
@param nameValues the list of name values
@return nameValues grouped | [
"Transform",
"grouped",
"into",
"a",
"map",
"of",
"name",
"to",
"a",
"linked",
"set",
"of",
"values"
] | 7804c08be9d91174e4af63dd6b56a375cb96d99e | https://github.com/gravityrd/jsondto/blob/7804c08be9d91174e4af63dd6b56a375cb96d99e/src/main/java/com/gravityrd/receng/web/webshop/jsondto/GravityNameValue.java#L32-L40 | train |
eFaps/eFaps-Kernel | src/main/java/org/efaps/db/store/AbstractStoreResource.java | AbstractStoreResource.setFileInfo | protected void setFileInfo(final String _filename,
final long _fileLength)
throws EFapsException
{
if (!_filename.equals(this.fileName) || _fileLength != this.fileLength) {
ConnectionResource res = null;
try {
res = Context.getThreadContext().getConnectionResource();
final AbstractDatabase<?> db = Context.getDbType();
final StringBuilder cmd = new StringBuilder().append(db.getSQLPart(SQLPart.UPDATE)).append(" ")
.append(db.getTableQuote()).append(AbstractStoreResource.TABLENAME_STORE)
.append(db.getTableQuote())
.append(" ").append(db.getSQLPart(SQLPart.SET)).append(" ")
.append(db.getColumnQuote())
.append(AbstractStoreResource.COLNAME_FILENAME)
.append(db.getColumnQuote()).append(db.getSQLPart(SQLPart.EQUAL)).append("? ")
.append(db.getSQLPart(SQLPart.COMMA))
.append(db.getColumnQuote())
.append(AbstractStoreResource.COLNAME_FILELENGTH)
.append(db.getColumnQuote()).append(db.getSQLPart(SQLPart.EQUAL)).append("? ")
.append(db.getSQLPart(SQLPart.WHERE)).append(" ")
.append(db.getColumnQuote()).append("ID").append(db.getColumnQuote())
.append(db.getSQLPart(SQLPart.EQUAL)).append(getGeneralID());
final PreparedStatement stmt = res.prepareStatement(cmd.toString());
try {
stmt.setString(1, _filename);
stmt.setLong(2, _fileLength);
stmt.execute();
} finally {
stmt.close();
}
} catch (final EFapsException e) {
throw e;
} catch (final SQLException e) {
throw new EFapsException(JDBCStoreResource.class, "write.SQLException", e);
}
}
} | java | protected void setFileInfo(final String _filename,
final long _fileLength)
throws EFapsException
{
if (!_filename.equals(this.fileName) || _fileLength != this.fileLength) {
ConnectionResource res = null;
try {
res = Context.getThreadContext().getConnectionResource();
final AbstractDatabase<?> db = Context.getDbType();
final StringBuilder cmd = new StringBuilder().append(db.getSQLPart(SQLPart.UPDATE)).append(" ")
.append(db.getTableQuote()).append(AbstractStoreResource.TABLENAME_STORE)
.append(db.getTableQuote())
.append(" ").append(db.getSQLPart(SQLPart.SET)).append(" ")
.append(db.getColumnQuote())
.append(AbstractStoreResource.COLNAME_FILENAME)
.append(db.getColumnQuote()).append(db.getSQLPart(SQLPart.EQUAL)).append("? ")
.append(db.getSQLPart(SQLPart.COMMA))
.append(db.getColumnQuote())
.append(AbstractStoreResource.COLNAME_FILELENGTH)
.append(db.getColumnQuote()).append(db.getSQLPart(SQLPart.EQUAL)).append("? ")
.append(db.getSQLPart(SQLPart.WHERE)).append(" ")
.append(db.getColumnQuote()).append("ID").append(db.getColumnQuote())
.append(db.getSQLPart(SQLPart.EQUAL)).append(getGeneralID());
final PreparedStatement stmt = res.prepareStatement(cmd.toString());
try {
stmt.setString(1, _filename);
stmt.setLong(2, _fileLength);
stmt.execute();
} finally {
stmt.close();
}
} catch (final EFapsException e) {
throw e;
} catch (final SQLException e) {
throw new EFapsException(JDBCStoreResource.class, "write.SQLException", e);
}
}
} | [
"protected",
"void",
"setFileInfo",
"(",
"final",
"String",
"_filename",
",",
"final",
"long",
"_fileLength",
")",
"throws",
"EFapsException",
"{",
"if",
"(",
"!",
"_filename",
".",
"equals",
"(",
"this",
".",
"fileName",
")",
"||",
"_fileLength",
"!=",
"thi... | Set the info for the file in this store reosurce.
@param _filename name of the file
@param _fileLength length of the file
@throws EFapsException on error | [
"Set",
"the",
"info",
"for",
"the",
"file",
"in",
"this",
"store",
"reosurce",
"."
] | 04b96548f518c2386a93f5ec2b9349f9b9063859 | https://github.com/eFaps/eFaps-Kernel/blob/04b96548f518c2386a93f5ec2b9349f9b9063859/src/main/java/org/efaps/db/store/AbstractStoreResource.java#L253-L291 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.