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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/sspi/NTDSAPIWrapper.java | NTDSAPIWrapper.DsMakeSpn | public String DsMakeSpn(String serviceClass, String serviceName, String instanceName,
short instancePort, String referrer) throws LastErrorException {
IntByReference spnLength = new IntByReference(2048);
char[] spn = new char[spnLength.getValue()];
final int ret =
NTDSAPI.instance.DsMakeSpnW(
new WString(serviceClass),
new WString(serviceName),
instanceName == null ? null : new WString(instanceName),
instancePort,
referrer == null ? null : new WString(referrer),
spnLength,
spn);
if (ret != NTDSAPI.ERROR_SUCCESS) {
/* Should've thrown LastErrorException, but just in case */
throw new RuntimeException("NTDSAPI DsMakeSpn call failed with " + ret);
}
return new String(spn, 0, spnLength.getValue());
} | java | public String DsMakeSpn(String serviceClass, String serviceName, String instanceName,
short instancePort, String referrer) throws LastErrorException {
IntByReference spnLength = new IntByReference(2048);
char[] spn = new char[spnLength.getValue()];
final int ret =
NTDSAPI.instance.DsMakeSpnW(
new WString(serviceClass),
new WString(serviceName),
instanceName == null ? null : new WString(instanceName),
instancePort,
referrer == null ? null : new WString(referrer),
spnLength,
spn);
if (ret != NTDSAPI.ERROR_SUCCESS) {
/* Should've thrown LastErrorException, but just in case */
throw new RuntimeException("NTDSAPI DsMakeSpn call failed with " + ret);
}
return new String(spn, 0, spnLength.getValue());
} | [
"public",
"String",
"DsMakeSpn",
"(",
"String",
"serviceClass",
",",
"String",
"serviceName",
",",
"String",
"instanceName",
",",
"short",
"instancePort",
",",
"String",
"referrer",
")",
"throws",
"LastErrorException",
"{",
"IntByReference",
"spnLength",
"=",
"new",... | Convenience wrapper for NTDSAPI DsMakeSpn with Java friendly string and exception handling.
@param serviceClass See MSDN
@param serviceName See MSDN
@param instanceName See MSDN
@param instancePort See MSDN
@param referrer See MSDN
@return SPN generated
@throws LastErrorException If buffer too small or parameter incorrect
@see <a href="https://msdn.microsoft.com/en-us/library/ms676007(v=vs.85).aspx">
https://msdn.microsoft.com/en-us/library/ms676007(v=vs.85).aspx</a> | [
"Convenience",
"wrapper",
"for",
"NTDSAPI",
"DsMakeSpn",
"with",
"Java",
"friendly",
"string",
"and",
"exception",
"handling",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/sspi/NTDSAPIWrapper.java#L30-L51 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java | ByteConverter.int8 | public static long int8(byte[] bytes, int idx) {
return
((long) (bytes[idx + 0] & 255) << 56)
+ ((long) (bytes[idx + 1] & 255) << 48)
+ ((long) (bytes[idx + 2] & 255) << 40)
+ ((long) (bytes[idx + 3] & 255) << 32)
+ ((long) (bytes[idx + 4] & 255) << 24)
+ ((long) (bytes[idx + 5] & 255) << 16)
+ ((long) (bytes[idx + 6] & 255) << 8)
+ (bytes[idx + 7] & 255);
} | java | public static long int8(byte[] bytes, int idx) {
return
((long) (bytes[idx + 0] & 255) << 56)
+ ((long) (bytes[idx + 1] & 255) << 48)
+ ((long) (bytes[idx + 2] & 255) << 40)
+ ((long) (bytes[idx + 3] & 255) << 32)
+ ((long) (bytes[idx + 4] & 255) << 24)
+ ((long) (bytes[idx + 5] & 255) << 16)
+ ((long) (bytes[idx + 6] & 255) << 8)
+ (bytes[idx + 7] & 255);
} | [
"public",
"static",
"long",
"int8",
"(",
"byte",
"[",
"]",
"bytes",
",",
"int",
"idx",
")",
"{",
"return",
"(",
"(",
"long",
")",
"(",
"bytes",
"[",
"idx",
"+",
"0",
"]",
"&",
"255",
")",
"<<",
"56",
")",
"+",
"(",
"(",
"long",
")",
"(",
"b... | Parses a long value from the byte array.
@param bytes The byte array to parse.
@param idx The starting index of the parse in the byte array.
@return parsed long value. | [
"Parses",
"a",
"long",
"value",
"from",
"the",
"byte",
"array",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java#L26-L36 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java | ByteConverter.int4 | public static int int4(byte[] bytes, int idx) {
return
((bytes[idx] & 255) << 24)
+ ((bytes[idx + 1] & 255) << 16)
+ ((bytes[idx + 2] & 255) << 8)
+ ((bytes[idx + 3] & 255));
} | java | public static int int4(byte[] bytes, int idx) {
return
((bytes[idx] & 255) << 24)
+ ((bytes[idx + 1] & 255) << 16)
+ ((bytes[idx + 2] & 255) << 8)
+ ((bytes[idx + 3] & 255));
} | [
"public",
"static",
"int",
"int4",
"(",
"byte",
"[",
"]",
"bytes",
",",
"int",
"idx",
")",
"{",
"return",
"(",
"(",
"bytes",
"[",
"idx",
"]",
"&",
"255",
")",
"<<",
"24",
")",
"+",
"(",
"(",
"bytes",
"[",
"idx",
"+",
"1",
"]",
"&",
"255",
"... | Parses an int value from the byte array.
@param bytes The byte array to parse.
@param idx The starting index of the parse in the byte array.
@return parsed int value. | [
"Parses",
"an",
"int",
"value",
"from",
"the",
"byte",
"array",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java#L45-L51 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java | ByteConverter.int8 | public static void int8(byte[] target, int idx, long value) {
target[idx + 0] = (byte) (value >>> 56);
target[idx + 1] = (byte) (value >>> 48);
target[idx + 2] = (byte) (value >>> 40);
target[idx + 3] = (byte) (value >>> 32);
target[idx + 4] = (byte) (value >>> 24);
target[idx + 5] = (byte) (value >>> 16);
target[idx + 6] = (byte) (value >>> 8);
target[idx + 7] = (byte) value;
} | java | public static void int8(byte[] target, int idx, long value) {
target[idx + 0] = (byte) (value >>> 56);
target[idx + 1] = (byte) (value >>> 48);
target[idx + 2] = (byte) (value >>> 40);
target[idx + 3] = (byte) (value >>> 32);
target[idx + 4] = (byte) (value >>> 24);
target[idx + 5] = (byte) (value >>> 16);
target[idx + 6] = (byte) (value >>> 8);
target[idx + 7] = (byte) value;
} | [
"public",
"static",
"void",
"int8",
"(",
"byte",
"[",
"]",
"target",
",",
"int",
"idx",
",",
"long",
"value",
")",
"{",
"target",
"[",
"idx",
"+",
"0",
"]",
"=",
"(",
"byte",
")",
"(",
"value",
">>>",
"56",
")",
";",
"target",
"[",
"idx",
"+",
... | Encodes a long value to the byte array.
@param target The byte array to encode to.
@param idx The starting index in the byte array.
@param value The value to encode. | [
"Encodes",
"a",
"long",
"value",
"to",
"the",
"byte",
"array",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/util/ByteConverter.java#L106-L115 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Encoding.java | Encoding.getJVMEncoding | public static Encoding getJVMEncoding(String jvmEncoding) {
if ("UTF-8".equals(jvmEncoding)) {
return new UTF8Encoding();
}
if (Charset.isSupported(jvmEncoding)) {
return new Encoding(jvmEncoding);
} else {
return DEFAULT_ENCODING;
}
} | java | public static Encoding getJVMEncoding(String jvmEncoding) {
if ("UTF-8".equals(jvmEncoding)) {
return new UTF8Encoding();
}
if (Charset.isSupported(jvmEncoding)) {
return new Encoding(jvmEncoding);
} else {
return DEFAULT_ENCODING;
}
} | [
"public",
"static",
"Encoding",
"getJVMEncoding",
"(",
"String",
"jvmEncoding",
")",
"{",
"if",
"(",
"\"UTF-8\"",
".",
"equals",
"(",
"jvmEncoding",
")",
")",
"{",
"return",
"new",
"UTF8Encoding",
"(",
")",
";",
"}",
"if",
"(",
"Charset",
".",
"isSupported... | Construct an Encoding for a given JVM encoding.
@param jvmEncoding the name of the JVM encoding
@return an Encoding instance for the specified encoding, or an Encoding instance for the
default JVM encoding if the specified encoding is unavailable. | [
"Construct",
"an",
"Encoding",
"for",
"a",
"given",
"JVM",
"encoding",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Encoding.java#L135-L144 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Encoding.java | Encoding.getDatabaseEncoding | public static Encoding getDatabaseEncoding(String databaseEncoding) {
if ("UTF8".equals(databaseEncoding)) {
return UTF8_ENCODING;
}
// If the backend encoding is known and there is a suitable
// encoding in the JVM we use that. Otherwise we fall back
// to the default encoding of the JVM.
String[] candidates = encodings.get(databaseEncoding);
if (candidates != null) {
for (String candidate : candidates) {
LOGGER.log(Level.FINEST, "Search encoding candidate {0}", candidate);
if (Charset.isSupported(candidate)) {
return new Encoding(candidate);
}
}
}
// Try the encoding name directly -- maybe the charset has been
// provided by the user.
if (Charset.isSupported(databaseEncoding)) {
return new Encoding(databaseEncoding);
}
// Fall back to default JVM encoding.
LOGGER.log(Level.FINEST, "{0} encoding not found, returning default encoding", databaseEncoding);
return DEFAULT_ENCODING;
} | java | public static Encoding getDatabaseEncoding(String databaseEncoding) {
if ("UTF8".equals(databaseEncoding)) {
return UTF8_ENCODING;
}
// If the backend encoding is known and there is a suitable
// encoding in the JVM we use that. Otherwise we fall back
// to the default encoding of the JVM.
String[] candidates = encodings.get(databaseEncoding);
if (candidates != null) {
for (String candidate : candidates) {
LOGGER.log(Level.FINEST, "Search encoding candidate {0}", candidate);
if (Charset.isSupported(candidate)) {
return new Encoding(candidate);
}
}
}
// Try the encoding name directly -- maybe the charset has been
// provided by the user.
if (Charset.isSupported(databaseEncoding)) {
return new Encoding(databaseEncoding);
}
// Fall back to default JVM encoding.
LOGGER.log(Level.FINEST, "{0} encoding not found, returning default encoding", databaseEncoding);
return DEFAULT_ENCODING;
} | [
"public",
"static",
"Encoding",
"getDatabaseEncoding",
"(",
"String",
"databaseEncoding",
")",
"{",
"if",
"(",
"\"UTF8\"",
".",
"equals",
"(",
"databaseEncoding",
")",
")",
"{",
"return",
"UTF8_ENCODING",
";",
"}",
"// If the backend encoding is known and there is a sui... | Construct an Encoding for a given database encoding.
@param databaseEncoding the name of the database encoding
@return an Encoding instance for the specified encoding, or an Encoding instance for the
default JVM encoding if the specified encoding is unavailable. | [
"Construct",
"an",
"Encoding",
"for",
"a",
"given",
"database",
"encoding",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Encoding.java#L153-L179 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Encoding.java | Encoding.encode | public byte[] encode(String s) throws IOException {
if (s == null) {
return null;
}
return s.getBytes(encoding);
} | java | public byte[] encode(String s) throws IOException {
if (s == null) {
return null;
}
return s.getBytes(encoding);
} | [
"public",
"byte",
"[",
"]",
"encode",
"(",
"String",
"s",
")",
"throws",
"IOException",
"{",
"if",
"(",
"s",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"s",
".",
"getBytes",
"(",
"encoding",
")",
";",
"}"
] | Encode a string to an array of bytes.
@param s the string to encode
@return a bytearray containing the encoded string
@throws IOException if something goes wrong | [
"Encode",
"a",
"string",
"to",
"an",
"array",
"of",
"bytes",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Encoding.java#L197-L203 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Encoding.java | Encoding.decode | public String decode(byte[] encodedString, int offset, int length) throws IOException {
return new String(encodedString, offset, length, encoding);
} | java | public String decode(byte[] encodedString, int offset, int length) throws IOException {
return new String(encodedString, offset, length, encoding);
} | [
"public",
"String",
"decode",
"(",
"byte",
"[",
"]",
"encodedString",
",",
"int",
"offset",
",",
"int",
"length",
")",
"throws",
"IOException",
"{",
"return",
"new",
"String",
"(",
"encodedString",
",",
"offset",
",",
"length",
",",
"encoding",
")",
";",
... | Decode an array of bytes into a string.
@param encodedString a byte array containing the string to decode
@param offset the offset in <code>encodedString</code> of the first byte of the encoded
representation
@param length the length, in bytes, of the encoded representation
@return the decoded string
@throws IOException if something goes wrong | [
"Decode",
"an",
"array",
"of",
"bytes",
"into",
"a",
"string",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Encoding.java#L215-L217 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.getFunction | public static Method getFunction(String functionName) {
return functionMap.get("sql" + functionName.toLowerCase(Locale.US));
} | java | public static Method getFunction(String functionName) {
return functionMap.get("sql" + functionName.toLowerCase(Locale.US));
} | [
"public",
"static",
"Method",
"getFunction",
"(",
"String",
"functionName",
")",
"{",
"return",
"functionMap",
".",
"get",
"(",
"\"sql\"",
"+",
"functionName",
".",
"toLowerCase",
"(",
"Locale",
".",
"US",
")",
")",
";",
"}"
] | get Method object implementing the given function.
@param functionName name of the searched function
@return a Method object or null if not found | [
"get",
"Method",
"object",
"implementing",
"the",
"given",
"function",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L137-L139 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.sqlconcat | public static String sqlconcat(List<?> parsedArgs) {
StringBuilder buf = new StringBuilder();
buf.append('(');
for (int iArg = 0; iArg < parsedArgs.size(); iArg++) {
buf.append(parsedArgs.get(iArg));
if (iArg != (parsedArgs.size() - 1)) {
buf.append(" || ");
}
}
return buf.append(')').toString();
} | java | public static String sqlconcat(List<?> parsedArgs) {
StringBuilder buf = new StringBuilder();
buf.append('(');
for (int iArg = 0; iArg < parsedArgs.size(); iArg++) {
buf.append(parsedArgs.get(iArg));
if (iArg != (parsedArgs.size() - 1)) {
buf.append(" || ");
}
}
return buf.append(')').toString();
} | [
"public",
"static",
"String",
"sqlconcat",
"(",
"List",
"<",
"?",
">",
"parsedArgs",
")",
"{",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"buf",
".",
"append",
"(",
"'",
"'",
")",
";",
"for",
"(",
"int",
"iArg",
"=",
"0",
"... | concat translation.
@param parsedArgs arguments
@return sql call | [
"concat",
"translation",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L217-L227 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.sqlinsert | public static String sqlinsert(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() != 4) {
throw new PSQLException(GT.tr("{0} function takes four and only four argument.", "insert"),
PSQLState.SYNTAX_ERROR);
}
StringBuilder buf = new StringBuilder();
buf.append("overlay(");
buf.append(parsedArgs.get(0)).append(" placing ").append(parsedArgs.get(3));
buf.append(" from ").append(parsedArgs.get(1)).append(" for ").append(parsedArgs.get(2));
return buf.append(')').toString();
} | java | public static String sqlinsert(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() != 4) {
throw new PSQLException(GT.tr("{0} function takes four and only four argument.", "insert"),
PSQLState.SYNTAX_ERROR);
}
StringBuilder buf = new StringBuilder();
buf.append("overlay(");
buf.append(parsedArgs.get(0)).append(" placing ").append(parsedArgs.get(3));
buf.append(" from ").append(parsedArgs.get(1)).append(" for ").append(parsedArgs.get(2));
return buf.append(')').toString();
} | [
"public",
"static",
"String",
"sqlinsert",
"(",
"List",
"<",
"?",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"parsedArgs",
".",
"size",
"(",
")",
"!=",
"4",
")",
"{",
"throw",
"new",
"PSQLException",
"(",
"GT",
".",
"tr",
"(",
... | insert to overlay translation.
@param parsedArgs arguments
@return sql call
@throws SQLException if something wrong happens | [
"insert",
"to",
"overlay",
"translation",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L236-L246 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.sqllocate | public static String sqllocate(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() == 2) {
return "position(" + parsedArgs.get(0) + " in " + parsedArgs.get(1) + ")";
} else if (parsedArgs.size() == 3) {
String tmp = "position(" + parsedArgs.get(0) + " in substring(" + parsedArgs.get(1) + " from "
+ parsedArgs.get(2) + "))";
return "(" + parsedArgs.get(2) + "*sign(" + tmp + ")+" + tmp + ")";
} else {
throw new PSQLException(GT.tr("{0} function takes two or three arguments.", "locate"),
PSQLState.SYNTAX_ERROR);
}
} | java | public static String sqllocate(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() == 2) {
return "position(" + parsedArgs.get(0) + " in " + parsedArgs.get(1) + ")";
} else if (parsedArgs.size() == 3) {
String tmp = "position(" + parsedArgs.get(0) + " in substring(" + parsedArgs.get(1) + " from "
+ parsedArgs.get(2) + "))";
return "(" + parsedArgs.get(2) + "*sign(" + tmp + ")+" + tmp + ")";
} else {
throw new PSQLException(GT.tr("{0} function takes two or three arguments.", "locate"),
PSQLState.SYNTAX_ERROR);
}
} | [
"public",
"static",
"String",
"sqllocate",
"(",
"List",
"<",
"?",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"parsedArgs",
".",
"size",
"(",
")",
"==",
"2",
")",
"{",
"return",
"\"position(\"",
"+",
"parsedArgs",
".",
"get",
"(",
... | locate translation.
@param parsedArgs arguments
@return sql call
@throws SQLException if something wrong happens | [
"locate",
"translation",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L302-L313 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.sqlsubstring | public static String sqlsubstring(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() == 2) {
return "substr(" + parsedArgs.get(0) + "," + parsedArgs.get(1) + ")";
} else if (parsedArgs.size() == 3) {
return "substr(" + parsedArgs.get(0) + "," + parsedArgs.get(1) + "," + parsedArgs.get(2)
+ ")";
} else {
throw new PSQLException(GT.tr("{0} function takes two or three arguments.", "substring"),
PSQLState.SYNTAX_ERROR);
}
} | java | public static String sqlsubstring(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() == 2) {
return "substr(" + parsedArgs.get(0) + "," + parsedArgs.get(1) + ")";
} else if (parsedArgs.size() == 3) {
return "substr(" + parsedArgs.get(0) + "," + parsedArgs.get(1) + "," + parsedArgs.get(2)
+ ")";
} else {
throw new PSQLException(GT.tr("{0} function takes two or three arguments.", "substring"),
PSQLState.SYNTAX_ERROR);
}
} | [
"public",
"static",
"String",
"sqlsubstring",
"(",
"List",
"<",
"?",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"parsedArgs",
".",
"size",
"(",
")",
"==",
"2",
")",
"{",
"return",
"\"substr(\"",
"+",
"parsedArgs",
".",
"get",
"(",
... | substring to substr translation.
@param parsedArgs arguments
@return sql call
@throws SQLException if something wrong happens | [
"substring",
"to",
"substr",
"translation",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L377-L387 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.sqlcurdate | public static String sqlcurdate(List<?> parsedArgs) throws SQLException {
if (!parsedArgs.isEmpty()) {
throw new PSQLException(GT.tr("{0} function doesn''t take any argument.", "curdate"),
PSQLState.SYNTAX_ERROR);
}
return "current_date";
} | java | public static String sqlcurdate(List<?> parsedArgs) throws SQLException {
if (!parsedArgs.isEmpty()) {
throw new PSQLException(GT.tr("{0} function doesn''t take any argument.", "curdate"),
PSQLState.SYNTAX_ERROR);
}
return "current_date";
} | [
"public",
"static",
"String",
"sqlcurdate",
"(",
"List",
"<",
"?",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"!",
"parsedArgs",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"PSQLException",
"(",
"GT",
".",
"tr",
"(",
"\"{... | curdate to current_date translation.
@param parsedArgs arguments
@return sql call
@throws SQLException if something wrong happens | [
"curdate",
"to",
"current_date",
"translation",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L407-L413 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.sqlmonthname | public static String sqlmonthname(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() != 1) {
throw new PSQLException(GT.tr("{0} function takes one and only one argument.", "monthname"),
PSQLState.SYNTAX_ERROR);
}
return "to_char(" + parsedArgs.get(0) + ",'Month')";
} | java | public static String sqlmonthname(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() != 1) {
throw new PSQLException(GT.tr("{0} function takes one and only one argument.", "monthname"),
PSQLState.SYNTAX_ERROR);
}
return "to_char(" + parsedArgs.get(0) + ",'Month')";
} | [
"public",
"static",
"String",
"sqlmonthname",
"(",
"List",
"<",
"?",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"parsedArgs",
".",
"size",
"(",
")",
"!=",
"1",
")",
"{",
"throw",
"new",
"PSQLException",
"(",
"GT",
".",
"tr",
"(",... | monthname translation.
@param parsedArgs arguments
@return sql call
@throws SQLException if something wrong happens | [
"monthname",
"translation",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L522-L528 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java | EscapedFunctions.sqltimestampadd | public static String sqltimestampadd(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() != 3) {
throw new PSQLException(
GT.tr("{0} function takes three and only three arguments.", "timestampadd"),
PSQLState.SYNTAX_ERROR);
}
String interval = EscapedFunctions.constantToInterval(parsedArgs.get(0).toString(),
parsedArgs.get(1).toString());
StringBuilder buf = new StringBuilder();
buf.append("(").append(interval).append("+");
buf.append(parsedArgs.get(2)).append(")");
return buf.toString();
} | java | public static String sqltimestampadd(List<?> parsedArgs) throws SQLException {
if (parsedArgs.size() != 3) {
throw new PSQLException(
GT.tr("{0} function takes three and only three arguments.", "timestampadd"),
PSQLState.SYNTAX_ERROR);
}
String interval = EscapedFunctions.constantToInterval(parsedArgs.get(0).toString(),
parsedArgs.get(1).toString());
StringBuilder buf = new StringBuilder();
buf.append("(").append(interval).append("+");
buf.append(parsedArgs.get(2)).append(")");
return buf.toString();
} | [
"public",
"static",
"String",
"sqltimestampadd",
"(",
"List",
"<",
"?",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"parsedArgs",
".",
"size",
"(",
")",
"!=",
"3",
")",
"{",
"throw",
"new",
"PSQLException",
"(",
"GT",
".",
"tr",
"... | time stamp add.
@param parsedArgs arguments
@return sql call
@throws SQLException if something wrong happens | [
"time",
"stamp",
"add",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions.java#L581-L593 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.getFunction | public static Method getFunction(String functionName) {
Method method = FUNCTION_MAP.get(functionName);
if (method != null) {
return method;
}
String nameLower = functionName.toLowerCase(Locale.US);
if (nameLower == functionName) {
// Input name was in lower case, the function is not there
return null;
}
method = FUNCTION_MAP.get(nameLower);
if (method != null && FUNCTION_MAP.size() < 1000) {
// Avoid OutOfMemoryError in case input function names are randomized
// The number of methods is finite, however the number of upper-lower case combinations
// is quite a few (e.g. substr, Substr, sUbstr, SUbstr, etc).
FUNCTION_MAP.putIfAbsent(functionName, method);
}
return method;
} | java | public static Method getFunction(String functionName) {
Method method = FUNCTION_MAP.get(functionName);
if (method != null) {
return method;
}
String nameLower = functionName.toLowerCase(Locale.US);
if (nameLower == functionName) {
// Input name was in lower case, the function is not there
return null;
}
method = FUNCTION_MAP.get(nameLower);
if (method != null && FUNCTION_MAP.size() < 1000) {
// Avoid OutOfMemoryError in case input function names are randomized
// The number of methods is finite, however the number of upper-lower case combinations
// is quite a few (e.g. substr, Substr, sUbstr, SUbstr, etc).
FUNCTION_MAP.putIfAbsent(functionName, method);
}
return method;
} | [
"public",
"static",
"Method",
"getFunction",
"(",
"String",
"functionName",
")",
"{",
"Method",
"method",
"=",
"FUNCTION_MAP",
".",
"get",
"(",
"functionName",
")",
";",
"if",
"(",
"method",
"!=",
"null",
")",
"{",
"return",
"method",
";",
"}",
"String",
... | get Method object implementing the given function
@param functionName name of the searched function
@return a Method object or null if not found | [
"get",
"Method",
"object",
"implementing",
"the",
"given",
"function"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L58-L76 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqlceiling | public static void sqlceiling(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "ceil(", "ceiling", parsedArgs);
} | java | public static void sqlceiling(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "ceil(", "ceiling", parsedArgs);
} | [
"public",
"static",
"void",
"sqlceiling",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"singleArgumentFunctionCall",
"(",
"buf",
",",
"\"ceil(\"",
",",
"\"ceiling\"",
",",
"... | ceiling to ceil translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"ceiling",
"to",
"ceil",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L87-L89 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqllog | public static void sqllog(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "ln(", "log", parsedArgs);
} | java | public static void sqllog(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "ln(", "log", parsedArgs);
} | [
"public",
"static",
"void",
"sqllog",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"singleArgumentFunctionCall",
"(",
"buf",
",",
"\"ln(\"",
",",
"\"log\"",
",",
"parsedArgs... | log to ln translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"log",
"to",
"ln",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L98-L100 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqllog10 | public static void sqllog10(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "log(", "log10", parsedArgs);
} | java | public static void sqllog10(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "log(", "log10", parsedArgs);
} | [
"public",
"static",
"void",
"sqllog10",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"singleArgumentFunctionCall",
"(",
"buf",
",",
"\"log(\"",
",",
"\"log10\"",
",",
"parse... | log10 to log translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"log10",
"to",
"log",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L109-L111 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqlpower | public static void sqlpower(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
twoArgumentsFunctionCall(buf, "pow(", "power", parsedArgs);
} | java | public static void sqlpower(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
twoArgumentsFunctionCall(buf, "pow(", "power", parsedArgs);
} | [
"public",
"static",
"void",
"sqlpower",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"twoArgumentsFunctionCall",
"(",
"buf",
",",
"\"pow(\"",
",",
"\"power\"",
",",
"parsedA... | power to pow translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"power",
"to",
"pow",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L120-L122 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqltruncate | public static void sqltruncate(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
twoArgumentsFunctionCall(buf, "trunc(", "truncate", parsedArgs);
} | java | public static void sqltruncate(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
twoArgumentsFunctionCall(buf, "trunc(", "truncate", parsedArgs);
} | [
"public",
"static",
"void",
"sqltruncate",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"twoArgumentsFunctionCall",
"(",
"buf",
",",
"\"trunc(\"",
",",
"\"truncate\"",
",",
... | truncate to trunc translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"truncate",
"to",
"trunc",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L131-L133 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqlchar | public static void sqlchar(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "chr(", "char", parsedArgs);
} | java | public static void sqlchar(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "chr(", "char", parsedArgs);
} | [
"public",
"static",
"void",
"sqlchar",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"singleArgumentFunctionCall",
"(",
"buf",
",",
"\"chr(\"",
",",
"\"char\"",
",",
"parsedA... | char to chr translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"char",
"to",
"chr",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L144-L146 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqllcase | public static void sqllcase(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "lower(", "lcase", parsedArgs);
} | java | public static void sqllcase(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "lower(", "lcase", parsedArgs);
} | [
"public",
"static",
"void",
"sqllcase",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"singleArgumentFunctionCall",
"(",
"buf",
",",
"\"lower(\"",
",",
"\"lcase\"",
",",
"par... | lcase to lower translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"lcase",
"to",
"lower",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L183-L185 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqlucase | public static void sqlucase(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "upper(", "ucase", parsedArgs);
} | java | public static void sqlucase(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
singleArgumentFunctionCall(buf, "upper(", "ucase", parsedArgs);
} | [
"public",
"static",
"void",
"sqlucase",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"singleArgumentFunctionCall",
"(",
"buf",
",",
"\"upper(\"",
",",
"\"ucase\"",
",",
"par... | ucase to upper translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"ucase",
"to",
"upper",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L320-L322 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqlcurdate | public static void sqlcurdate(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
zeroArgumentFunctionCall(buf, "current_date", "curdate", parsedArgs);
} | java | public static void sqlcurdate(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
zeroArgumentFunctionCall(buf, "current_date", "curdate", parsedArgs);
} | [
"public",
"static",
"void",
"sqlcurdate",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"zeroArgumentFunctionCall",
"(",
"buf",
",",
"\"current_date\"",
",",
"\"curdate\"",
","... | curdate to current_date translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"curdate",
"to",
"current_date",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L331-L333 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqlcurtime | public static void sqlcurtime(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
zeroArgumentFunctionCall(buf, "current_time", "curtime", parsedArgs);
} | java | public static void sqlcurtime(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
zeroArgumentFunctionCall(buf, "current_time", "curtime", parsedArgs);
} | [
"public",
"static",
"void",
"sqlcurtime",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"zeroArgumentFunctionCall",
"(",
"buf",
",",
"\"current_time\"",
",",
"\"curtime\"",
","... | curtime to current_time translation
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"curtime",
"to",
"current_time",
"translation"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L342-L344 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqltimestampadd | public static void sqltimestampadd(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
if (parsedArgs.size() != 3) {
throw new PSQLException(
GT.tr("{0} function takes three and only three arguments.", "timestampadd"),
PSQLState.SYNTAX_ERROR);
}
buf.append('(');
appendInterval(buf, parsedArgs.get(0).toString(), parsedArgs.get(1).toString());
buf.append('+').append(parsedArgs.get(2)).append(')');
} | java | public static void sqltimestampadd(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
if (parsedArgs.size() != 3) {
throw new PSQLException(
GT.tr("{0} function takes three and only three arguments.", "timestampadd"),
PSQLState.SYNTAX_ERROR);
}
buf.append('(');
appendInterval(buf, parsedArgs.get(0).toString(), parsedArgs.get(1).toString());
buf.append('+').append(parsedArgs.get(2)).append(')');
} | [
"public",
"static",
"void",
"sqltimestampadd",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"parsedArgs",
".",
"size",
"(",
")",
"!=",
"3",
")",
"{",
"throw... | time stamp add
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"time",
"stamp",
"add"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L497-L506 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.areSameTsi | private static boolean areSameTsi(String a, String b) {
return a.length() == b.length() && b.length() > SQL_TSI_ROOT.length()
&& a.regionMatches(true, SQL_TSI_ROOT.length(), b, SQL_TSI_ROOT.length(), b.length() - SQL_TSI_ROOT.length());
} | java | private static boolean areSameTsi(String a, String b) {
return a.length() == b.length() && b.length() > SQL_TSI_ROOT.length()
&& a.regionMatches(true, SQL_TSI_ROOT.length(), b, SQL_TSI_ROOT.length(), b.length() - SQL_TSI_ROOT.length());
} | [
"private",
"static",
"boolean",
"areSameTsi",
"(",
"String",
"a",
",",
"String",
"b",
")",
"{",
"return",
"a",
".",
"length",
"(",
")",
"==",
"b",
".",
"length",
"(",
")",
"&&",
"b",
".",
"length",
"(",
")",
">",
"SQL_TSI_ROOT",
".",
"length",
"(",... | Compares two TSI intervals. It is
@param a first interval to compare
@param b second interval to compare
@return true when both intervals are equal (case insensitive) | [
"Compares",
"two",
"TSI",
"intervals",
".",
"It",
"is"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L546-L549 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java | EscapedFunctions2.sqltimestampdiff | public static void sqltimestampdiff(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
if (parsedArgs.size() != 3) {
throw new PSQLException(
GT.tr("{0} function takes three and only three arguments.", "timestampdiff"),
PSQLState.SYNTAX_ERROR);
}
buf.append("extract( ")
.append(constantToDatePart(buf, parsedArgs.get(0).toString()))
.append(" from (")
.append(parsedArgs.get(2))
.append("-")
.append(parsedArgs.get(1))
.append("))");
} | java | public static void sqltimestampdiff(StringBuilder buf, List<? extends CharSequence> parsedArgs) throws SQLException {
if (parsedArgs.size() != 3) {
throw new PSQLException(
GT.tr("{0} function takes three and only three arguments.", "timestampdiff"),
PSQLState.SYNTAX_ERROR);
}
buf.append("extract( ")
.append(constantToDatePart(buf, parsedArgs.get(0).toString()))
.append(" from (")
.append(parsedArgs.get(2))
.append("-")
.append(parsedArgs.get(1))
.append("))");
} | [
"public",
"static",
"void",
"sqltimestampdiff",
"(",
"StringBuilder",
"buf",
",",
"List",
"<",
"?",
"extends",
"CharSequence",
">",
"parsedArgs",
")",
"throws",
"SQLException",
"{",
"if",
"(",
"parsedArgs",
".",
"size",
"(",
")",
"!=",
"3",
")",
"{",
"thro... | time stamp diff
@param buf The buffer to append into
@param parsedArgs arguments
@throws SQLException if something wrong happens | [
"time",
"stamp",
"diff"
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/EscapedFunctions2.java#L567-L580 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java | PgPreparedStatement.setPGobject | private void setPGobject(int parameterIndex, PGobject x) throws SQLException {
String typename = x.getType();
int oid = connection.getTypeInfo().getPGType(typename);
if (oid == Oid.UNSPECIFIED) {
throw new PSQLException(GT.tr("Unknown type {0}.", typename),
PSQLState.INVALID_PARAMETER_TYPE);
}
if ((x instanceof PGBinaryObject) && connection.binaryTransferSend(oid)) {
PGBinaryObject binObj = (PGBinaryObject) x;
byte[] data = new byte[binObj.lengthInBytes()];
binObj.toBytes(data, 0);
bindBytes(parameterIndex, data, oid);
} else {
setString(parameterIndex, x.getValue(), oid);
}
} | java | private void setPGobject(int parameterIndex, PGobject x) throws SQLException {
String typename = x.getType();
int oid = connection.getTypeInfo().getPGType(typename);
if (oid == Oid.UNSPECIFIED) {
throw new PSQLException(GT.tr("Unknown type {0}.", typename),
PSQLState.INVALID_PARAMETER_TYPE);
}
if ((x instanceof PGBinaryObject) && connection.binaryTransferSend(oid)) {
PGBinaryObject binObj = (PGBinaryObject) x;
byte[] data = new byte[binObj.lengthInBytes()];
binObj.toBytes(data, 0);
bindBytes(parameterIndex, data, oid);
} else {
setString(parameterIndex, x.getValue(), oid);
}
} | [
"private",
"void",
"setPGobject",
"(",
"int",
"parameterIndex",
",",
"PGobject",
"x",
")",
"throws",
"SQLException",
"{",
"String",
"typename",
"=",
"x",
".",
"getType",
"(",
")",
";",
"int",
"oid",
"=",
"connection",
".",
"getTypeInfo",
"(",
")",
".",
"... | Helper method for setting parameters to PGobject subclasses. | [
"Helper",
"method",
"for",
"setting",
"parameters",
"to",
"PGobject",
"subclasses",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java#L444-L460 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java | TypeInfoCache.convertArrayToBaseOid | protected synchronized int convertArrayToBaseOid(int oid) {
Integer i = pgArrayToPgType.get(oid);
if (i == null) {
return oid;
}
return i;
} | java | protected synchronized int convertArrayToBaseOid(int oid) {
Integer i = pgArrayToPgType.get(oid);
if (i == null) {
return oid;
}
return i;
} | [
"protected",
"synchronized",
"int",
"convertArrayToBaseOid",
"(",
"int",
"oid",
")",
"{",
"Integer",
"i",
"=",
"pgArrayToPgType",
".",
"get",
"(",
"oid",
")",
";",
"if",
"(",
"i",
"==",
"null",
")",
"{",
"return",
"oid",
";",
"}",
"return",
"i",
";",
... | Return the oid of the array's base element if it's an array, if not return the provided oid.
This doesn't do any database lookups, so it's only useful for the originally provided type
mappings. This is fine for it's intended uses where we only have intimate knowledge of types
that are already known to the driver.
@param oid input oid
@return oid of the array's base element or the provided oid (if not array) | [
"Return",
"the",
"oid",
"of",
"the",
"array",
"s",
"base",
"element",
"if",
"it",
"s",
"an",
"array",
"if",
"not",
"return",
"the",
"provided",
"oid",
".",
"This",
"doesn",
"t",
"do",
"any",
"database",
"lookups",
"so",
"it",
"s",
"only",
"useful",
"... | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java#L454-L460 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java | TypeInfoCache.requiresQuotingSqlType | public boolean requiresQuotingSqlType(int sqlType) throws SQLException {
switch (sqlType) {
case Types.BIGINT:
case Types.DOUBLE:
case Types.FLOAT:
case Types.INTEGER:
case Types.REAL:
case Types.SMALLINT:
case Types.TINYINT:
case Types.NUMERIC:
case Types.DECIMAL:
return false;
}
return true;
} | java | public boolean requiresQuotingSqlType(int sqlType) throws SQLException {
switch (sqlType) {
case Types.BIGINT:
case Types.DOUBLE:
case Types.FLOAT:
case Types.INTEGER:
case Types.REAL:
case Types.SMALLINT:
case Types.TINYINT:
case Types.NUMERIC:
case Types.DECIMAL:
return false;
}
return true;
} | [
"public",
"boolean",
"requiresQuotingSqlType",
"(",
"int",
"sqlType",
")",
"throws",
"SQLException",
"{",
"switch",
"(",
"sqlType",
")",
"{",
"case",
"Types",
".",
"BIGINT",
":",
"case",
"Types",
".",
"DOUBLE",
":",
"case",
"Types",
".",
"FLOAT",
":",
"cas... | Returns true if particular sqlType requires quoting.
This method is used internally by the driver, so it might disappear without notice.
@param sqlType sql type as in java.sql.Types
@return true if the type requires quoting
@throws SQLException if something goes wrong | [
"Returns",
"true",
"if",
"particular",
"sqlType",
"requires",
"quoting",
".",
"This",
"method",
"is",
"used",
"internally",
"by",
"the",
"driver",
"so",
"it",
"might",
"disappear",
"without",
"notice",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java#L854-L868 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.hasMessagePending | public boolean hasMessagePending() throws IOException {
if (pgInput.available() > 0) {
return true;
}
// In certain cases, available returns 0, yet there are bytes
long now = System.currentTimeMillis();
if (now < nextStreamAvailableCheckTime && minStreamAvailableCheckDelay != 0) {
// Do not use ".peek" too often
return false;
}
nextStreamAvailableCheckTime = now + minStreamAvailableCheckDelay;
int soTimeout = getNetworkTimeout();
setNetworkTimeout(1);
try {
return pgInput.peek() != -1;
} catch (SocketTimeoutException e) {
return false;
} finally {
setNetworkTimeout(soTimeout);
}
} | java | public boolean hasMessagePending() throws IOException {
if (pgInput.available() > 0) {
return true;
}
// In certain cases, available returns 0, yet there are bytes
long now = System.currentTimeMillis();
if (now < nextStreamAvailableCheckTime && minStreamAvailableCheckDelay != 0) {
// Do not use ".peek" too often
return false;
}
nextStreamAvailableCheckTime = now + minStreamAvailableCheckDelay;
int soTimeout = getNetworkTimeout();
setNetworkTimeout(1);
try {
return pgInput.peek() != -1;
} catch (SocketTimeoutException e) {
return false;
} finally {
setNetworkTimeout(soTimeout);
}
} | [
"public",
"boolean",
"hasMessagePending",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"pgInput",
".",
"available",
"(",
")",
">",
"0",
")",
"{",
"return",
"true",
";",
"}",
"// In certain cases, available returns 0, yet there are bytes",
"long",
"now",
"=",... | Check for pending backend messages without blocking. Might return false when there actually are
messages waiting, depending on the characteristics of the underlying socket. This is used to
detect asynchronous notifies from the backend, when available.
@return true if there is a pending backend message
@throws IOException if something wrong happens | [
"Check",
"for",
"pending",
"backend",
"messages",
"without",
"blocking",
".",
"Might",
"return",
"false",
"when",
"there",
"actually",
"are",
"messages",
"waiting",
"depending",
"on",
"the",
"characteristics",
"of",
"the",
"underlying",
"socket",
".",
"This",
"i... | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L117-L137 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.setEncoding | public void setEncoding(Encoding encoding) throws IOException {
if (this.encoding != null && this.encoding.name().equals(encoding.name())) {
return;
}
// Close down any old writer.
if (encodingWriter != null) {
encodingWriter.close();
}
this.encoding = encoding;
// Intercept flush() downcalls from the writer; our caller
// will call PGStream.flush() as needed.
OutputStream interceptor = new FilterOutputStream(pgOutput) {
public void flush() throws IOException {
}
public void close() throws IOException {
super.flush();
}
};
encodingWriter = encoding.getEncodingWriter(interceptor);
} | java | public void setEncoding(Encoding encoding) throws IOException {
if (this.encoding != null && this.encoding.name().equals(encoding.name())) {
return;
}
// Close down any old writer.
if (encodingWriter != null) {
encodingWriter.close();
}
this.encoding = encoding;
// Intercept flush() downcalls from the writer; our caller
// will call PGStream.flush() as needed.
OutputStream interceptor = new FilterOutputStream(pgOutput) {
public void flush() throws IOException {
}
public void close() throws IOException {
super.flush();
}
};
encodingWriter = encoding.getEncodingWriter(interceptor);
} | [
"public",
"void",
"setEncoding",
"(",
"Encoding",
"encoding",
")",
"throws",
"IOException",
"{",
"if",
"(",
"this",
".",
"encoding",
"!=",
"null",
"&&",
"this",
".",
"encoding",
".",
"name",
"(",
")",
".",
"equals",
"(",
"encoding",
".",
"name",
"(",
"... | Change the encoding used by this connection.
@param encoding the new encoding to use
@throws IOException if something goes wrong | [
"Change",
"the",
"encoding",
"used",
"by",
"this",
"connection",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L177-L200 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.sendInteger4 | public void sendInteger4(int val) throws IOException {
int4Buf[0] = (byte) (val >>> 24);
int4Buf[1] = (byte) (val >>> 16);
int4Buf[2] = (byte) (val >>> 8);
int4Buf[3] = (byte) (val);
pgOutput.write(int4Buf);
} | java | public void sendInteger4(int val) throws IOException {
int4Buf[0] = (byte) (val >>> 24);
int4Buf[1] = (byte) (val >>> 16);
int4Buf[2] = (byte) (val >>> 8);
int4Buf[3] = (byte) (val);
pgOutput.write(int4Buf);
} | [
"public",
"void",
"sendInteger4",
"(",
"int",
"val",
")",
"throws",
"IOException",
"{",
"int4Buf",
"[",
"0",
"]",
"=",
"(",
"byte",
")",
"(",
"val",
">>>",
"24",
")",
";",
"int4Buf",
"[",
"1",
"]",
"=",
"(",
"byte",
")",
"(",
"val",
">>>",
"16",
... | Sends a 4-byte integer to the back end.
@param val the integer to be sent
@throws IOException if an I/O error occurs | [
"Sends",
"a",
"4",
"-",
"byte",
"integer",
"to",
"the",
"back",
"end",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L236-L242 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.receiveInteger4 | public int receiveInteger4() throws IOException {
if (pgInput.read(int4Buf) != 4) {
throw new EOFException();
}
return (int4Buf[0] & 0xFF) << 24 | (int4Buf[1] & 0xFF) << 16 | (int4Buf[2] & 0xFF) << 8
| int4Buf[3] & 0xFF;
} | java | public int receiveInteger4() throws IOException {
if (pgInput.read(int4Buf) != 4) {
throw new EOFException();
}
return (int4Buf[0] & 0xFF) << 24 | (int4Buf[1] & 0xFF) << 16 | (int4Buf[2] & 0xFF) << 8
| int4Buf[3] & 0xFF;
} | [
"public",
"int",
"receiveInteger4",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"pgInput",
".",
"read",
"(",
"int4Buf",
")",
"!=",
"4",
")",
"{",
"throw",
"new",
"EOFException",
"(",
")",
";",
"}",
"return",
"(",
"int4Buf",
"[",
"0",
"]",
"&",... | Receives a four byte integer from the backend.
@return the integer received from the backend
@throws IOException if an I/O error occurs | [
"Receives",
"a",
"four",
"byte",
"integer",
"from",
"the",
"backend",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L334-L341 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.receiveString | public String receiveString(int len) throws IOException {
if (!pgInput.ensureBytes(len)) {
throw new EOFException();
}
String res = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
pgInput.skip(len);
return res;
} | java | public String receiveString(int len) throws IOException {
if (!pgInput.ensureBytes(len)) {
throw new EOFException();
}
String res = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
pgInput.skip(len);
return res;
} | [
"public",
"String",
"receiveString",
"(",
"int",
"len",
")",
"throws",
"IOException",
"{",
"if",
"(",
"!",
"pgInput",
".",
"ensureBytes",
"(",
"len",
")",
")",
"{",
"throw",
"new",
"EOFException",
"(",
")",
";",
"}",
"String",
"res",
"=",
"encoding",
"... | Receives a fixed-size string from the backend.
@param len the length of the string to receive, in bytes.
@return the decoded string
@throws IOException if something wrong happens | [
"Receives",
"a",
"fixed",
"-",
"size",
"string",
"from",
"the",
"backend",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L364-L372 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.receiveErrorString | public EncodingPredictor.DecodeResult receiveErrorString(int len) throws IOException {
if (!pgInput.ensureBytes(len)) {
throw new EOFException();
}
EncodingPredictor.DecodeResult res;
try {
String value = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
// no autodetect warning as the message was converted on its own
res = new EncodingPredictor.DecodeResult(value, null);
} catch (IOException e) {
res = EncodingPredictor.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
if (res == null) {
Encoding enc = Encoding.defaultEncoding();
String value = enc.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
res = new EncodingPredictor.DecodeResult(value, enc.name());
}
}
pgInput.skip(len);
return res;
} | java | public EncodingPredictor.DecodeResult receiveErrorString(int len) throws IOException {
if (!pgInput.ensureBytes(len)) {
throw new EOFException();
}
EncodingPredictor.DecodeResult res;
try {
String value = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
// no autodetect warning as the message was converted on its own
res = new EncodingPredictor.DecodeResult(value, null);
} catch (IOException e) {
res = EncodingPredictor.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
if (res == null) {
Encoding enc = Encoding.defaultEncoding();
String value = enc.decode(pgInput.getBuffer(), pgInput.getIndex(), len);
res = new EncodingPredictor.DecodeResult(value, enc.name());
}
}
pgInput.skip(len);
return res;
} | [
"public",
"EncodingPredictor",
".",
"DecodeResult",
"receiveErrorString",
"(",
"int",
"len",
")",
"throws",
"IOException",
"{",
"if",
"(",
"!",
"pgInput",
".",
"ensureBytes",
"(",
"len",
")",
")",
"{",
"throw",
"new",
"EOFException",
"(",
")",
";",
"}",
"E... | Receives a fixed-size string from the backend, and tries to avoid "UTF-8 decode failed"
errors.
@param len the length of the string to receive, in bytes.
@return the decoded string
@throws IOException if something wrong happens | [
"Receives",
"a",
"fixed",
"-",
"size",
"string",
"from",
"the",
"backend",
"and",
"tries",
"to",
"avoid",
"UTF",
"-",
"8",
"decode",
"failed",
"errors",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L382-L402 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.receiveString | public String receiveString() throws IOException {
int len = pgInput.scanCStringLength();
String res = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len - 1);
pgInput.skip(len);
return res;
} | java | public String receiveString() throws IOException {
int len = pgInput.scanCStringLength();
String res = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len - 1);
pgInput.skip(len);
return res;
} | [
"public",
"String",
"receiveString",
"(",
")",
"throws",
"IOException",
"{",
"int",
"len",
"=",
"pgInput",
".",
"scanCStringLength",
"(",
")",
";",
"String",
"res",
"=",
"encoding",
".",
"decode",
"(",
"pgInput",
".",
"getBuffer",
"(",
")",
",",
"pgInput",... | Receives a null-terminated string from the backend. If we don't see a null, then we assume
something has gone wrong.
@return string from back end
@throws IOException if an I/O error occurs, or end of file | [
"Receives",
"a",
"null",
"-",
"terminated",
"string",
"from",
"the",
"backend",
".",
"If",
"we",
"don",
"t",
"see",
"a",
"null",
"then",
"we",
"assume",
"something",
"has",
"gone",
"wrong",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L411-L416 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.receiveTupleV3 | public byte[][] receiveTupleV3() throws IOException, OutOfMemoryError {
// TODO: use msgSize
int msgSize = receiveInteger4();
int nf = receiveInteger2();
byte[][] answer = new byte[nf][];
OutOfMemoryError oom = null;
for (int i = 0; i < nf; ++i) {
int size = receiveInteger4();
if (size != -1) {
try {
answer[i] = new byte[size];
receive(answer[i], 0, size);
} catch (OutOfMemoryError oome) {
oom = oome;
skip(size);
}
}
}
if (oom != null) {
throw oom;
}
return answer;
} | java | public byte[][] receiveTupleV3() throws IOException, OutOfMemoryError {
// TODO: use msgSize
int msgSize = receiveInteger4();
int nf = receiveInteger2();
byte[][] answer = new byte[nf][];
OutOfMemoryError oom = null;
for (int i = 0; i < nf; ++i) {
int size = receiveInteger4();
if (size != -1) {
try {
answer[i] = new byte[size];
receive(answer[i], 0, size);
} catch (OutOfMemoryError oome) {
oom = oome;
skip(size);
}
}
}
if (oom != null) {
throw oom;
}
return answer;
} | [
"public",
"byte",
"[",
"]",
"[",
"]",
"receiveTupleV3",
"(",
")",
"throws",
"IOException",
",",
"OutOfMemoryError",
"{",
"// TODO: use msgSize",
"int",
"msgSize",
"=",
"receiveInteger4",
"(",
")",
";",
"int",
"nf",
"=",
"receiveInteger2",
"(",
")",
";",
"byt... | Read a tuple from the back end. A tuple is a two dimensional array of bytes. This variant reads
the V3 protocol's tuple representation.
@return tuple from the back end
@throws IOException if a data I/O error occurs | [
"Read",
"a",
"tuple",
"from",
"the",
"back",
"end",
".",
"A",
"tuple",
"is",
"a",
"two",
"dimensional",
"array",
"of",
"bytes",
".",
"This",
"variant",
"reads",
"the",
"V3",
"protocol",
"s",
"tuple",
"representation",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L425-L450 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.receive | public void receive(byte[] buf, int off, int siz) throws IOException {
int s = 0;
while (s < siz) {
int w = pgInput.read(buf, off + s, siz - s);
if (w < 0) {
throw new EOFException();
}
s += w;
}
} | java | public void receive(byte[] buf, int off, int siz) throws IOException {
int s = 0;
while (s < siz) {
int w = pgInput.read(buf, off + s, siz - s);
if (w < 0) {
throw new EOFException();
}
s += w;
}
} | [
"public",
"void",
"receive",
"(",
"byte",
"[",
"]",
"buf",
",",
"int",
"off",
",",
"int",
"siz",
")",
"throws",
"IOException",
"{",
"int",
"s",
"=",
"0",
";",
"while",
"(",
"s",
"<",
"siz",
")",
"{",
"int",
"w",
"=",
"pgInput",
".",
"read",
"("... | Reads in a given number of bytes from the backend.
@param buf buffer to store result
@param off offset in buffer
@param siz number of bytes to read
@throws IOException if a data I/O error occurs | [
"Reads",
"in",
"a",
"given",
"number",
"of",
"bytes",
"from",
"the",
"backend",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L473-L483 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.sendStream | public void sendStream(InputStream inStream, int remaining) throws IOException {
int expectedLength = remaining;
if (streamBuffer == null) {
streamBuffer = new byte[8192];
}
while (remaining > 0) {
int count = (remaining > streamBuffer.length ? streamBuffer.length : remaining);
int readCount;
try {
readCount = inStream.read(streamBuffer, 0, count);
if (readCount < 0) {
throw new EOFException(
GT.tr("Premature end of input stream, expected {0} bytes, but only read {1}.",
expectedLength, expectedLength - remaining));
}
} catch (IOException ioe) {
while (remaining > 0) {
send(streamBuffer, count);
remaining -= count;
count = (remaining > streamBuffer.length ? streamBuffer.length : remaining);
}
throw new PGBindException(ioe);
}
send(streamBuffer, readCount);
remaining -= readCount;
}
} | java | public void sendStream(InputStream inStream, int remaining) throws IOException {
int expectedLength = remaining;
if (streamBuffer == null) {
streamBuffer = new byte[8192];
}
while (remaining > 0) {
int count = (remaining > streamBuffer.length ? streamBuffer.length : remaining);
int readCount;
try {
readCount = inStream.read(streamBuffer, 0, count);
if (readCount < 0) {
throw new EOFException(
GT.tr("Premature end of input stream, expected {0} bytes, but only read {1}.",
expectedLength, expectedLength - remaining));
}
} catch (IOException ioe) {
while (remaining > 0) {
send(streamBuffer, count);
remaining -= count;
count = (remaining > streamBuffer.length ? streamBuffer.length : remaining);
}
throw new PGBindException(ioe);
}
send(streamBuffer, readCount);
remaining -= readCount;
}
} | [
"public",
"void",
"sendStream",
"(",
"InputStream",
"inStream",
",",
"int",
"remaining",
")",
"throws",
"IOException",
"{",
"int",
"expectedLength",
"=",
"remaining",
";",
"if",
"(",
"streamBuffer",
"==",
"null",
")",
"{",
"streamBuffer",
"=",
"new",
"byte",
... | Copy data from an input stream to the connection.
@param inStream the stream to read data from
@param remaining the number of bytes to copy
@throws IOException if a data I/O error occurs | [
"Copy",
"data",
"from",
"an",
"input",
"stream",
"to",
"the",
"connection",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L499-L528 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/PGStream.java | PGStream.receiveEOF | public void receiveEOF() throws SQLException, IOException {
int c = pgInput.read();
if (c < 0) {
return;
}
throw new PSQLException(GT.tr("Expected an EOF from server, got: {0}", c),
PSQLState.COMMUNICATION_ERROR);
} | java | public void receiveEOF() throws SQLException, IOException {
int c = pgInput.read();
if (c < 0) {
return;
}
throw new PSQLException(GT.tr("Expected an EOF from server, got: {0}", c),
PSQLState.COMMUNICATION_ERROR);
} | [
"public",
"void",
"receiveEOF",
"(",
")",
"throws",
"SQLException",
",",
"IOException",
"{",
"int",
"c",
"=",
"pgInput",
".",
"read",
"(",
")",
";",
"if",
"(",
"c",
"<",
"0",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"PSQLException",
"(",
"GT",
... | Consume an expected EOF from the backend.
@throws IOException if an I/O error occurs
@throws SQLException if we get something other than an EOF | [
"Consume",
"an",
"expected",
"EOF",
"from",
"the",
"backend",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/PGStream.java#L550-L557 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java | GlobalHostStatusTracker.reportHostStatus | public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
long now = currentTimeMillis();
synchronized (hostStatusMap) {
HostSpecStatus hostSpecStatus = hostStatusMap.get(hostSpec);
if (hostSpecStatus == null) {
hostSpecStatus = new HostSpecStatus(hostSpec);
hostStatusMap.put(hostSpec, hostSpecStatus);
}
hostSpecStatus.status = hostStatus;
hostSpecStatus.lastUpdated = now;
}
} | java | public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
long now = currentTimeMillis();
synchronized (hostStatusMap) {
HostSpecStatus hostSpecStatus = hostStatusMap.get(hostSpec);
if (hostSpecStatus == null) {
hostSpecStatus = new HostSpecStatus(hostSpec);
hostStatusMap.put(hostSpec, hostSpecStatus);
}
hostSpecStatus.status = hostStatus;
hostSpecStatus.lastUpdated = now;
}
} | [
"public",
"static",
"void",
"reportHostStatus",
"(",
"HostSpec",
"hostSpec",
",",
"HostStatus",
"hostStatus",
")",
"{",
"long",
"now",
"=",
"currentTimeMillis",
"(",
")",
";",
"synchronized",
"(",
"hostStatusMap",
")",
"{",
"HostSpecStatus",
"hostSpecStatus",
"=",... | Store the actual observed host status.
@param hostSpec The host whose status is known.
@param hostStatus Latest known status for the host. | [
"Store",
"the",
"actual",
"observed",
"host",
"status",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java#L30-L41 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java | GlobalHostStatusTracker.getCandidateHosts | static List<HostSpec> getCandidateHosts(HostSpec[] hostSpecs,
HostRequirement targetServerType, long hostRecheckMillis) {
List<HostSpec> candidates = new ArrayList<HostSpec>(hostSpecs.length);
long latestAllowedUpdate = currentTimeMillis() - hostRecheckMillis;
synchronized (hostStatusMap) {
for (HostSpec hostSpec : hostSpecs) {
HostSpecStatus hostInfo = hostStatusMap.get(hostSpec);
// candidates are nodes we do not know about and the nodes with correct type
if (hostInfo == null
|| hostInfo.lastUpdated < latestAllowedUpdate
|| targetServerType.allowConnectingTo(hostInfo.status)) {
candidates.add(hostSpec);
}
}
}
return candidates;
} | java | static List<HostSpec> getCandidateHosts(HostSpec[] hostSpecs,
HostRequirement targetServerType, long hostRecheckMillis) {
List<HostSpec> candidates = new ArrayList<HostSpec>(hostSpecs.length);
long latestAllowedUpdate = currentTimeMillis() - hostRecheckMillis;
synchronized (hostStatusMap) {
for (HostSpec hostSpec : hostSpecs) {
HostSpecStatus hostInfo = hostStatusMap.get(hostSpec);
// candidates are nodes we do not know about and the nodes with correct type
if (hostInfo == null
|| hostInfo.lastUpdated < latestAllowedUpdate
|| targetServerType.allowConnectingTo(hostInfo.status)) {
candidates.add(hostSpec);
}
}
}
return candidates;
} | [
"static",
"List",
"<",
"HostSpec",
">",
"getCandidateHosts",
"(",
"HostSpec",
"[",
"]",
"hostSpecs",
",",
"HostRequirement",
"targetServerType",
",",
"long",
"hostRecheckMillis",
")",
"{",
"List",
"<",
"HostSpec",
">",
"candidates",
"=",
"new",
"ArrayList",
"<",... | Returns a list of candidate hosts that have the required targetServerType.
@param hostSpecs The potential list of hosts.
@param targetServerType The required target server type.
@param hostRecheckMillis How stale information is allowed.
@return candidate hosts to connect to. | [
"Returns",
"a",
"list",
"of",
"candidate",
"hosts",
"that",
"have",
"the",
"required",
"targetServerType",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/hostchooser/GlobalHostStatusTracker.java#L51-L67 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java | SSPIClient.isSSPISupported | @Override
public boolean isSSPISupported() {
try {
/*
* SSPI is windows-only. Attempt to use JNA to identify the platform. If Waffle is missing we
* won't have JNA and this will throw a NoClassDefFoundError.
*/
if (!Platform.isWindows()) {
LOGGER.log(Level.FINE, "SSPI not supported: non-Windows host");
return false;
}
/* Waffle must be on the CLASSPATH */
Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");
return true;
} catch (NoClassDefFoundError ex) {
LOGGER.log(Level.WARNING, "SSPI unavailable (no Waffle/JNA libraries?)", ex);
return false;
} catch (ClassNotFoundException ex) {
LOGGER.log(Level.WARNING, "SSPI unavailable (no Waffle/JNA libraries?)", ex);
return false;
}
} | java | @Override
public boolean isSSPISupported() {
try {
/*
* SSPI is windows-only. Attempt to use JNA to identify the platform. If Waffle is missing we
* won't have JNA and this will throw a NoClassDefFoundError.
*/
if (!Platform.isWindows()) {
LOGGER.log(Level.FINE, "SSPI not supported: non-Windows host");
return false;
}
/* Waffle must be on the CLASSPATH */
Class.forName("waffle.windows.auth.impl.WindowsSecurityContextImpl");
return true;
} catch (NoClassDefFoundError ex) {
LOGGER.log(Level.WARNING, "SSPI unavailable (no Waffle/JNA libraries?)", ex);
return false;
} catch (ClassNotFoundException ex) {
LOGGER.log(Level.WARNING, "SSPI unavailable (no Waffle/JNA libraries?)", ex);
return false;
}
} | [
"@",
"Override",
"public",
"boolean",
"isSSPISupported",
"(",
")",
"{",
"try",
"{",
"/*\n * SSPI is windows-only. Attempt to use JNA to identify the platform. If Waffle is missing we\n * won't have JNA and this will throw a NoClassDefFoundError.\n */",
"if",
"(",
"!",
"... | Test whether we can attempt SSPI authentication. If false, do not attempt to call any other
SSPIClient methods.
@return true if it's safe to attempt SSPI authentication | [
"Test",
"whether",
"we",
"can",
"attempt",
"SSPI",
"authentication",
".",
"If",
"false",
"do",
"not",
"attempt",
"to",
"call",
"any",
"other",
"SSPIClient",
"methods",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java#L79-L100 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java | SSPIClient.continueSSPI | @Override
public void continueSSPI(int msgLength) throws SQLException, IOException {
if (sspiContext == null) {
throw new IllegalStateException("Cannot continue SSPI authentication that we didn't begin");
}
LOGGER.log(Level.FINEST, "Continuing SSPI negotiation");
/* Read the response token from the server */
byte[] receivedToken = pgStream.receive(msgLength);
SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, receivedToken);
sspiContext.initialize(sspiContext.getHandle(), continueToken, targetName);
/*
* Now send the response token. If negotiation is complete there may be zero bytes to send, in
* which case we shouldn't send a reply as the server is not expecting one; see fe-auth.c in
* libpq for details.
*/
byte[] responseToken = sspiContext.getToken();
if (responseToken.length > 0) {
sendSSPIResponse(responseToken);
LOGGER.log(Level.FINEST, "Sent SSPI negotiation continuation message");
} else {
LOGGER.log(Level.FINEST, "SSPI authentication complete, no reply required");
}
} | java | @Override
public void continueSSPI(int msgLength) throws SQLException, IOException {
if (sspiContext == null) {
throw new IllegalStateException("Cannot continue SSPI authentication that we didn't begin");
}
LOGGER.log(Level.FINEST, "Continuing SSPI negotiation");
/* Read the response token from the server */
byte[] receivedToken = pgStream.receive(msgLength);
SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, receivedToken);
sspiContext.initialize(sspiContext.getHandle(), continueToken, targetName);
/*
* Now send the response token. If negotiation is complete there may be zero bytes to send, in
* which case we shouldn't send a reply as the server is not expecting one; see fe-auth.c in
* libpq for details.
*/
byte[] responseToken = sspiContext.getToken();
if (responseToken.length > 0) {
sendSSPIResponse(responseToken);
LOGGER.log(Level.FINEST, "Sent SSPI negotiation continuation message");
} else {
LOGGER.log(Level.FINEST, "SSPI authentication complete, no reply required");
}
} | [
"@",
"Override",
"public",
"void",
"continueSSPI",
"(",
"int",
"msgLength",
")",
"throws",
"SQLException",
",",
"IOException",
"{",
"if",
"(",
"sspiContext",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Cannot continue SSPI authentication... | Continue an existing authentication conversation with the back-end in resonse to an
authentication request of type AUTH_REQ_GSS_CONT.
@param msgLength Length of message to read, excluding length word and message type word
@throws SQLException if something wrong happens
@throws IOException if something wrong happens | [
"Continue",
"an",
"existing",
"authentication",
"conversation",
"with",
"the",
"back",
"-",
"end",
"in",
"resonse",
"to",
"an",
"authentication",
"request",
"of",
"type",
"AUTH_REQ_GSS_CONT",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java#L181-L209 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java | SSPIClient.dispose | @Override
public void dispose() {
if (sspiContext != null) {
sspiContext.dispose();
sspiContext = null;
}
if (clientCredentials != null) {
clientCredentials.dispose();
clientCredentials = null;
}
} | java | @Override
public void dispose() {
if (sspiContext != null) {
sspiContext.dispose();
sspiContext = null;
}
if (clientCredentials != null) {
clientCredentials.dispose();
clientCredentials = null;
}
} | [
"@",
"Override",
"public",
"void",
"dispose",
"(",
")",
"{",
"if",
"(",
"sspiContext",
"!=",
"null",
")",
"{",
"sspiContext",
".",
"dispose",
"(",
")",
";",
"sspiContext",
"=",
"null",
";",
"}",
"if",
"(",
"clientCredentials",
"!=",
"null",
")",
"{",
... | Clean up native win32 resources after completion or failure of SSPI authentication. This
SSPIClient instance becomes unusable after disposal. | [
"Clean",
"up",
"native",
"win32",
"resources",
"after",
"completion",
"or",
"failure",
"of",
"SSPI",
"authentication",
".",
"This",
"SSPIClient",
"instance",
"becomes",
"unusable",
"after",
"disposal",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/sspi/SSPIClient.java#L227-L237 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/ds/common/BaseDataSource.java | BaseDataSource.getConnection | public Connection getConnection(String user, String password) throws SQLException {
try {
Connection con = DriverManager.getConnection(getUrl(), user, password);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}",
new Object[] {getDescription(), user, getUrl()});
}
return con;
} catch (SQLException e) {
LOGGER.log(Level.FINE, "Failed to create a {0} for {1} at {2}: {3}",
new Object[] {getDescription(), user, getUrl(), e});
throw e;
}
} | java | public Connection getConnection(String user, String password) throws SQLException {
try {
Connection con = DriverManager.getConnection(getUrl(), user, password);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}",
new Object[] {getDescription(), user, getUrl()});
}
return con;
} catch (SQLException e) {
LOGGER.log(Level.FINE, "Failed to create a {0} for {1} at {2}: {3}",
new Object[] {getDescription(), user, getUrl(), e});
throw e;
}
} | [
"public",
"Connection",
"getConnection",
"(",
"String",
"user",
",",
"String",
"password",
")",
"throws",
"SQLException",
"{",
"try",
"{",
"Connection",
"con",
"=",
"DriverManager",
".",
"getConnection",
"(",
"getUrl",
"(",
")",
",",
"user",
",",
"password",
... | Gets a connection to the PostgreSQL database. The database is identified by the DataSource
properties serverName, databaseName, and portNumber. The user to connect as is identified by
the arguments user and password, which override the DataSource properties by the same name.
@param user user
@param password password
@return A valid database connection.
@throws SQLException Occurs when the database connection cannot be established. | [
"Gets",
"a",
"connection",
"to",
"the",
"PostgreSQL",
"database",
".",
"The",
"database",
"is",
"identified",
"by",
"the",
"DataSource",
"properties",
"serverName",
"databaseName",
"and",
"portNumber",
".",
"The",
"user",
"to",
"connect",
"as",
"is",
"identified... | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/ds/common/BaseDataSource.java#L95-L108 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/geometric/PGpoint.java | PGpoint.toBytes | public void toBytes(byte[] b, int offset) {
ByteConverter.float8(b, offset, x);
ByteConverter.float8(b, offset + 8, y);
} | java | public void toBytes(byte[] b, int offset) {
ByteConverter.float8(b, offset, x);
ByteConverter.float8(b, offset + 8, y);
} | [
"public",
"void",
"toBytes",
"(",
"byte",
"[",
"]",
"b",
",",
"int",
"offset",
")",
"{",
"ByteConverter",
".",
"float8",
"(",
"b",
",",
"offset",
",",
"x",
")",
";",
"ByteConverter",
".",
"float8",
"(",
"b",
",",
"offset",
"+",
"8",
",",
"y",
")"... | Populate the byte array with PGpoint in the binary syntax expected by org.postgresql. | [
"Populate",
"the",
"byte",
"array",
"with",
"PGpoint",
"in",
"the",
"binary",
"syntax",
"expected",
"by",
"org",
".",
"postgresql",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/geometric/PGpoint.java#L121-L124 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LibPQFactory.java | LibPQFactory.verifyHostName | @Deprecated
public static boolean verifyHostName(String hostname, String pattern) {
String canonicalHostname;
if (hostname.startsWith("[") && hostname.endsWith("]")) {
// IPv6 address like [2001:db8:0:1:1:1:1:1]
canonicalHostname = hostname.substring(1, hostname.length() - 1);
} else {
// This converts unicode domain name to ASCII
try {
canonicalHostname = IDN.toASCII(hostname);
} catch (IllegalArgumentException e) {
// e.g. hostname is invalid
return false;
}
}
return PGjdbcHostnameVerifier.INSTANCE.verifyHostName(canonicalHostname, pattern);
} | java | @Deprecated
public static boolean verifyHostName(String hostname, String pattern) {
String canonicalHostname;
if (hostname.startsWith("[") && hostname.endsWith("]")) {
// IPv6 address like [2001:db8:0:1:1:1:1:1]
canonicalHostname = hostname.substring(1, hostname.length() - 1);
} else {
// This converts unicode domain name to ASCII
try {
canonicalHostname = IDN.toASCII(hostname);
} catch (IllegalArgumentException e) {
// e.g. hostname is invalid
return false;
}
}
return PGjdbcHostnameVerifier.INSTANCE.verifyHostName(canonicalHostname, pattern);
} | [
"@",
"Deprecated",
"public",
"static",
"boolean",
"verifyHostName",
"(",
"String",
"hostname",
",",
"String",
"pattern",
")",
"{",
"String",
"canonicalHostname",
";",
"if",
"(",
"hostname",
".",
"startsWith",
"(",
"\"[\"",
")",
"&&",
"hostname",
".",
"endsWith... | Verifies if given hostname matches pattern.
@deprecated use {@link PGjdbcHostnameVerifier}
@param hostname input hostname
@param pattern domain name pattern
@return true when domain matches pattern | [
"Verifies",
"if",
"given",
"hostname",
"matches",
"pattern",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/ssl/jdbc4/LibPQFactory.java#L45-L61 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/geometric/PGpath.java | PGpath.getValue | public String getValue() {
StringBuilder b = new StringBuilder(open ? "[" : "(");
for (int p = 0; p < points.length; p++) {
if (p > 0) {
b.append(",");
}
b.append(points[p].toString());
}
b.append(open ? "]" : ")");
return b.toString();
} | java | public String getValue() {
StringBuilder b = new StringBuilder(open ? "[" : "(");
for (int p = 0; p < points.length; p++) {
if (p > 0) {
b.append(",");
}
b.append(points[p].toString());
}
b.append(open ? "]" : ")");
return b.toString();
} | [
"public",
"String",
"getValue",
"(",
")",
"{",
"StringBuilder",
"b",
"=",
"new",
"StringBuilder",
"(",
"open",
"?",
"\"[\"",
":",
"\"(\"",
")",
";",
"for",
"(",
"int",
"p",
"=",
"0",
";",
"p",
"<",
"points",
".",
"length",
";",
"p",
"++",
")",
"{... | This returns the path in the syntax expected by org.postgresql. | [
"This",
"returns",
"the",
"path",
"in",
"the",
"syntax",
"expected",
"by",
"org",
".",
"postgresql",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/geometric/PGpath.java#L132-L144 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseDeleteKeyword | public static boolean parseDeleteKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 'd'
&& (query[offset + 1] | 32) == 'e'
&& (query[offset + 2] | 32) == 'l'
&& (query[offset + 3] | 32) == 'e'
&& (query[offset + 4] | 32) == 't'
&& (query[offset + 5] | 32) == 'e';
} | java | public static boolean parseDeleteKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 'd'
&& (query[offset + 1] | 32) == 'e'
&& (query[offset + 2] | 32) == 'l'
&& (query[offset + 3] | 32) == 'e'
&& (query[offset + 4] | 32) == 't'
&& (query[offset + 5] | 32) == 'e';
} | [
"public",
"static",
"boolean",
"parseDeleteKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"6",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
... | Parse string to check presence of DELETE keyword regardless of case. The initial character is
assumed to have been matched.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"DELETE",
"keyword",
"regardless",
"of",
"case",
".",
"The",
"initial",
"character",
"is",
"assumed",
"to",
"have",
"been",
"matched",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L562-L573 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseInsertKeyword | public static boolean parseInsertKeyword(final char[] query, int offset) {
if (query.length < (offset + 7)) {
return false;
}
return (query[offset] | 32) == 'i'
&& (query[offset + 1] | 32) == 'n'
&& (query[offset + 2] | 32) == 's'
&& (query[offset + 3] | 32) == 'e'
&& (query[offset + 4] | 32) == 'r'
&& (query[offset + 5] | 32) == 't';
} | java | public static boolean parseInsertKeyword(final char[] query, int offset) {
if (query.length < (offset + 7)) {
return false;
}
return (query[offset] | 32) == 'i'
&& (query[offset + 1] | 32) == 'n'
&& (query[offset + 2] | 32) == 's'
&& (query[offset + 3] | 32) == 'e'
&& (query[offset + 4] | 32) == 'r'
&& (query[offset + 5] | 32) == 't';
} | [
"public",
"static",
"boolean",
"parseInsertKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"7",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
... | Parse string to check presence of INSERT keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"INSERT",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L582-L593 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseMoveKeyword | public static boolean parseMoveKeyword(final char[] query, int offset) {
if (query.length < (offset + 4)) {
return false;
}
return (query[offset] | 32) == 'm'
&& (query[offset + 1] | 32) == 'o'
&& (query[offset + 2] | 32) == 'v'
&& (query[offset + 3] | 32) == 'e';
} | java | public static boolean parseMoveKeyword(final char[] query, int offset) {
if (query.length < (offset + 4)) {
return false;
}
return (query[offset] | 32) == 'm'
&& (query[offset + 1] | 32) == 'o'
&& (query[offset + 2] | 32) == 'v'
&& (query[offset + 3] | 32) == 'e';
} | [
"public",
"static",
"boolean",
"parseMoveKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"4",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
... | Parse string to check presence of MOVE keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"MOVE",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L602-L611 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseReturningKeyword | public static boolean parseReturningKeyword(final char[] query, int offset) {
if (query.length < (offset + 9)) {
return false;
}
return (query[offset] | 32) == 'r'
&& (query[offset + 1] | 32) == 'e'
&& (query[offset + 2] | 32) == 't'
&& (query[offset + 3] | 32) == 'u'
&& (query[offset + 4] | 32) == 'r'
&& (query[offset + 5] | 32) == 'n'
&& (query[offset + 6] | 32) == 'i'
&& (query[offset + 7] | 32) == 'n'
&& (query[offset + 8] | 32) == 'g';
} | java | public static boolean parseReturningKeyword(final char[] query, int offset) {
if (query.length < (offset + 9)) {
return false;
}
return (query[offset] | 32) == 'r'
&& (query[offset + 1] | 32) == 'e'
&& (query[offset + 2] | 32) == 't'
&& (query[offset + 3] | 32) == 'u'
&& (query[offset + 4] | 32) == 'r'
&& (query[offset + 5] | 32) == 'n'
&& (query[offset + 6] | 32) == 'i'
&& (query[offset + 7] | 32) == 'n'
&& (query[offset + 8] | 32) == 'g';
} | [
"public",
"static",
"boolean",
"parseReturningKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"9",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(... | Parse string to check presence of RETURNING keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"RETURNING",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L620-L634 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseSelectKeyword | public static boolean parseSelectKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 's'
&& (query[offset + 1] | 32) == 'e'
&& (query[offset + 2] | 32) == 'l'
&& (query[offset + 3] | 32) == 'e'
&& (query[offset + 4] | 32) == 'c'
&& (query[offset + 5] | 32) == 't';
} | java | public static boolean parseSelectKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 's'
&& (query[offset + 1] | 32) == 'e'
&& (query[offset + 2] | 32) == 'l'
&& (query[offset + 3] | 32) == 'e'
&& (query[offset + 4] | 32) == 'c'
&& (query[offset + 5] | 32) == 't';
} | [
"public",
"static",
"boolean",
"parseSelectKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"6",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
... | Parse string to check presence of SELECT keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"SELECT",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L643-L654 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseUpdateKeyword | public static boolean parseUpdateKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 'u'
&& (query[offset + 1] | 32) == 'p'
&& (query[offset + 2] | 32) == 'd'
&& (query[offset + 3] | 32) == 'a'
&& (query[offset + 4] | 32) == 't'
&& (query[offset + 5] | 32) == 'e';
} | java | public static boolean parseUpdateKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 'u'
&& (query[offset + 1] | 32) == 'p'
&& (query[offset + 2] | 32) == 'd'
&& (query[offset + 3] | 32) == 'a'
&& (query[offset + 4] | 32) == 't'
&& (query[offset + 5] | 32) == 'e';
} | [
"public",
"static",
"boolean",
"parseUpdateKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"6",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
... | Parse string to check presence of UPDATE keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"UPDATE",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L663-L674 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseValuesKeyword | public static boolean parseValuesKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 'v'
&& (query[offset + 1] | 32) == 'a'
&& (query[offset + 2] | 32) == 'l'
&& (query[offset + 3] | 32) == 'u'
&& (query[offset + 4] | 32) == 'e'
&& (query[offset + 5] | 32) == 's';
} | java | public static boolean parseValuesKeyword(final char[] query, int offset) {
if (query.length < (offset + 6)) {
return false;
}
return (query[offset] | 32) == 'v'
&& (query[offset + 1] | 32) == 'a'
&& (query[offset + 2] | 32) == 'l'
&& (query[offset + 3] | 32) == 'u'
&& (query[offset + 4] | 32) == 'e'
&& (query[offset + 5] | 32) == 's';
} | [
"public",
"static",
"boolean",
"parseValuesKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"6",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
... | Parse string to check presence of VALUES keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"VALUES",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L683-L694 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseWithKeyword | public static boolean parseWithKeyword(final char[] query, int offset) {
if (query.length < (offset + 4)) {
return false;
}
return (query[offset] | 32) == 'w'
&& (query[offset + 1] | 32) == 'i'
&& (query[offset + 2] | 32) == 't'
&& (query[offset + 3] | 32) == 'h';
} | java | public static boolean parseWithKeyword(final char[] query, int offset) {
if (query.length < (offset + 4)) {
return false;
}
return (query[offset] | 32) == 'w'
&& (query[offset + 1] | 32) == 'i'
&& (query[offset + 2] | 32) == 't'
&& (query[offset + 3] | 32) == 'h';
} | [
"public",
"static",
"boolean",
"parseWithKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"4",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
... | Parse string to check presence of WITH keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"WITH",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L723-L732 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.parseAsKeyword | public static boolean parseAsKeyword(final char[] query, int offset) {
if (query.length < (offset + 2)) {
return false;
}
return (query[offset] | 32) == 'a'
&& (query[offset + 1] | 32) == 's';
} | java | public static boolean parseAsKeyword(final char[] query, int offset) {
if (query.length < (offset + 2)) {
return false;
}
return (query[offset] | 32) == 'a'
&& (query[offset + 1] | 32) == 's';
} | [
"public",
"static",
"boolean",
"parseAsKeyword",
"(",
"final",
"char",
"[",
"]",
"query",
",",
"int",
"offset",
")",
"{",
"if",
"(",
"query",
".",
"length",
"<",
"(",
"offset",
"+",
"2",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"q... | Parse string to check presence of AS keyword regardless of case.
@param query char[] of the query statement
@param offset position of query to start checking
@return boolean indicates presence of word | [
"Parse",
"string",
"to",
"check",
"presence",
"of",
"AS",
"keyword",
"regardless",
"of",
"case",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L741-L748 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.subArraysEqual | private static boolean subArraysEqual(final char[] arr,
final int offA, final int offB,
final int len) {
if (offA < 0 || offB < 0
|| offA >= arr.length || offB >= arr.length
|| offA + len > arr.length || offB + len > arr.length) {
return false;
}
for (int i = 0; i < len; ++i) {
if (arr[offA + i] != arr[offB + i]) {
return false;
}
}
return true;
} | java | private static boolean subArraysEqual(final char[] arr,
final int offA, final int offB,
final int len) {
if (offA < 0 || offB < 0
|| offA >= arr.length || offB >= arr.length
|| offA + len > arr.length || offB + len > arr.length) {
return false;
}
for (int i = 0; i < len; ++i) {
if (arr[offA + i] != arr[offB + i]) {
return false;
}
}
return true;
} | [
"private",
"static",
"boolean",
"subArraysEqual",
"(",
"final",
"char",
"[",
"]",
"arr",
",",
"final",
"int",
"offA",
",",
"final",
"int",
"offB",
",",
"final",
"int",
"len",
")",
"{",
"if",
"(",
"offA",
"<",
"0",
"||",
"offB",
"<",
"0",
"||",
"off... | Compares two sub-arrays of the given character array for equalness. If the length is zero, the
result is true if and only if the offsets are within the bounds of the array.
@param arr a char array
@param offA first sub-array start offset
@param offB second sub-array start offset
@param len length of the sub arrays to compare
@return true if the sub-arrays are equal; false if not | [
"Compares",
"two",
"sub",
"-",
"arrays",
"of",
"the",
"given",
"character",
"array",
"for",
"equalness",
".",
"If",
"the",
"length",
"is",
"zero",
"the",
"result",
"is",
"true",
"if",
"and",
"only",
"if",
"the",
"offsets",
"are",
"within",
"the",
"bounds... | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L874-L890 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/core/Parser.java | Parser.escapeFunctionArguments | private static int escapeFunctionArguments(StringBuilder newsql, String functionName, char[] sql, int i,
boolean stdStrings)
throws SQLException {
// Maximum arity of functions in EscapedFunctions is 3
List<CharSequence> parsedArgs = new ArrayList<CharSequence>(3);
while (true) {
StringBuilder arg = new StringBuilder();
int lastPos = i;
i = parseSql(sql, i, arg, true, stdStrings);
if (i != lastPos) {
parsedArgs.add(arg);
}
if (i >= sql.length // should not happen
|| sql[i] != ',') {
break;
}
i++;
}
Method method = EscapedFunctions2.getFunction(functionName);
if (method == null) {
newsql.append(functionName);
EscapedFunctions2.appendCall(newsql, "(", ",", ")", parsedArgs);
return i;
}
try {
method.invoke(null, newsql, parsedArgs);
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
if (targetException instanceof SQLException) {
throw (SQLException) targetException;
} else {
throw new PSQLException(targetException.getMessage(), PSQLState.SYSTEM_ERROR);
}
} catch (IllegalAccessException e) {
throw new PSQLException(e.getMessage(), PSQLState.SYSTEM_ERROR);
}
return i;
} | java | private static int escapeFunctionArguments(StringBuilder newsql, String functionName, char[] sql, int i,
boolean stdStrings)
throws SQLException {
// Maximum arity of functions in EscapedFunctions is 3
List<CharSequence> parsedArgs = new ArrayList<CharSequence>(3);
while (true) {
StringBuilder arg = new StringBuilder();
int lastPos = i;
i = parseSql(sql, i, arg, true, stdStrings);
if (i != lastPos) {
parsedArgs.add(arg);
}
if (i >= sql.length // should not happen
|| sql[i] != ',') {
break;
}
i++;
}
Method method = EscapedFunctions2.getFunction(functionName);
if (method == null) {
newsql.append(functionName);
EscapedFunctions2.appendCall(newsql, "(", ",", ")", parsedArgs);
return i;
}
try {
method.invoke(null, newsql, parsedArgs);
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
if (targetException instanceof SQLException) {
throw (SQLException) targetException;
} else {
throw new PSQLException(targetException.getMessage(), PSQLState.SYSTEM_ERROR);
}
} catch (IllegalAccessException e) {
throw new PSQLException(e.getMessage(), PSQLState.SYSTEM_ERROR);
}
return i;
} | [
"private",
"static",
"int",
"escapeFunctionArguments",
"(",
"StringBuilder",
"newsql",
",",
"String",
"functionName",
",",
"char",
"[",
"]",
"sql",
",",
"int",
"i",
",",
"boolean",
"stdStrings",
")",
"throws",
"SQLException",
"{",
"// Maximum arity of functions in E... | Generate sql for escaped functions.
@param newsql destination StringBuilder
@param functionName the escaped function name
@param sql input SQL text (containing arguments of a function call with possible JDBC escapes)
@param i position in the input SQL
@param stdStrings whether standard_conforming_strings is on
@return the right PostgreSQL sql
@throws SQLException if something goes wrong | [
"Generate",
"sql",
"for",
"escaped",
"functions",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/core/Parser.java#L1306-L1343 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/xa/PGXAConnection.java | PGXAConnection.getConnection | @Override
public Connection getConnection() throws SQLException {
Connection conn = super.getConnection();
// When we're outside an XA transaction, autocommit
// is supposed to be true, per usual JDBC convention.
// When an XA transaction is in progress, it should be
// false.
if (state == State.IDLE) {
conn.setAutoCommit(true);
}
/*
* Wrap the connection in a proxy to forbid application from fiddling with transaction state
* directly during an XA transaction
*/
ConnectionHandler handler = new ConnectionHandler(conn);
return (Connection) Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[]{Connection.class, PGConnection.class}, handler);
} | java | @Override
public Connection getConnection() throws SQLException {
Connection conn = super.getConnection();
// When we're outside an XA transaction, autocommit
// is supposed to be true, per usual JDBC convention.
// When an XA transaction is in progress, it should be
// false.
if (state == State.IDLE) {
conn.setAutoCommit(true);
}
/*
* Wrap the connection in a proxy to forbid application from fiddling with transaction state
* directly during an XA transaction
*/
ConnectionHandler handler = new ConnectionHandler(conn);
return (Connection) Proxy.newProxyInstance(getClass().getClassLoader(),
new Class[]{Connection.class, PGConnection.class}, handler);
} | [
"@",
"Override",
"public",
"Connection",
"getConnection",
"(",
")",
"throws",
"SQLException",
"{",
"Connection",
"conn",
"=",
"super",
".",
"getConnection",
"(",
")",
";",
"// When we're outside an XA transaction, autocommit",
"// is supposed to be true, per usual JDBC conven... | XAConnection interface. | [
"XAConnection",
"interface",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/xa/PGXAConnection.java#L81-L100 | train |
pgjdbc/pgjdbc | pgjdbc/src/main/java/org/postgresql/xa/PGXAConnection.java | PGXAConnection.forget | @Override
public void forget(Xid xid) throws XAException {
throw new PGXAException(GT.tr("Heuristic commit/rollback not supported. forget xid={0}", xid),
XAException.XAER_NOTA);
} | java | @Override
public void forget(Xid xid) throws XAException {
throw new PGXAException(GT.tr("Heuristic commit/rollback not supported. forget xid={0}", xid),
XAException.XAER_NOTA);
} | [
"@",
"Override",
"public",
"void",
"forget",
"(",
"Xid",
"xid",
")",
"throws",
"XAException",
"{",
"throw",
"new",
"PGXAException",
"(",
"GT",
".",
"tr",
"(",
"\"Heuristic commit/rollback not supported. forget xid={0}\"",
",",
"xid",
")",
",",
"XAException",
".",
... | Does nothing, since we don't do heuristics. | [
"Does",
"nothing",
"since",
"we",
"don",
"t",
"do",
"heuristics",
"."
] | 95ba7b261e39754674c5817695ae5ebf9a341fae | https://github.com/pgjdbc/pgjdbc/blob/95ba7b261e39754674c5817695ae5ebf9a341fae/pgjdbc/src/main/java/org/postgresql/xa/PGXAConnection.java#L624-L628 | train |
Jacksgong/JKeyboardPanelSwitch | library/src/main/java/cn/dreamtobe/kpswitch/util/KeyboardUtil.java | KeyboardUtil.detach | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void detach(Activity activity, ViewTreeObserver.OnGlobalLayoutListener l) {
ViewGroup contentView = activity.findViewById(android.R.id.content);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
contentView.getViewTreeObserver().removeOnGlobalLayoutListener(l);
} else {
//noinspection deprecation
contentView.getViewTreeObserver().removeGlobalOnLayoutListener(l);
}
} | java | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void detach(Activity activity, ViewTreeObserver.OnGlobalLayoutListener l) {
ViewGroup contentView = activity.findViewById(android.R.id.content);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
contentView.getViewTreeObserver().removeOnGlobalLayoutListener(l);
} else {
//noinspection deprecation
contentView.getViewTreeObserver().removeGlobalOnLayoutListener(l);
}
} | [
"@",
"TargetApi",
"(",
"Build",
".",
"VERSION_CODES",
".",
"JELLY_BEAN",
")",
"public",
"static",
"void",
"detach",
"(",
"Activity",
"activity",
",",
"ViewTreeObserver",
".",
"OnGlobalLayoutListener",
"l",
")",
"{",
"ViewGroup",
"contentView",
"=",
"activity",
"... | Remove the OnGlobalLayoutListener from the activity root view
@param activity same activity used in {@link #attach} method
@param l ViewTreeObserver.OnGlobalLayoutListener returned by {@link #attach} method | [
"Remove",
"the",
"OnGlobalLayoutListener",
"from",
"the",
"activity",
"root",
"view"
] | 092128023e824c85da63540780c79088b37a0c74 | https://github.com/Jacksgong/JKeyboardPanelSwitch/blob/092128023e824c85da63540780c79088b37a0c74/library/src/main/java/cn/dreamtobe/kpswitch/util/KeyboardUtil.java#L210-L219 | train |
Jacksgong/JKeyboardPanelSwitch | app/src/main/java/cn/dreamtobe/kpswitch/demo/activity/MainActivity.java | MainActivity.onClickExtraThemeResolved | public void onClickExtraThemeResolved(final View view) {
final boolean fullScreenTheme = mFullScreenRb.isChecked();
Intent i = new Intent(this, ChattingResolvedHandleByPlaceholderActivity.class);
i.putExtra(KEY_FULL_SCREEN_THEME, fullScreenTheme);
startActivity(i);
} | java | public void onClickExtraThemeResolved(final View view) {
final boolean fullScreenTheme = mFullScreenRb.isChecked();
Intent i = new Intent(this, ChattingResolvedHandleByPlaceholderActivity.class);
i.putExtra(KEY_FULL_SCREEN_THEME, fullScreenTheme);
startActivity(i);
} | [
"public",
"void",
"onClickExtraThemeResolved",
"(",
"final",
"View",
"view",
")",
"{",
"final",
"boolean",
"fullScreenTheme",
"=",
"mFullScreenRb",
".",
"isChecked",
"(",
")",
";",
"Intent",
"i",
"=",
"new",
"Intent",
"(",
"this",
",",
"ChattingResolvedHandleByP... | Resolved for Full Screen Theme or Translucent Status Theme. | [
"Resolved",
"for",
"Full",
"Screen",
"Theme",
"or",
"Translucent",
"Status",
"Theme",
"."
] | 092128023e824c85da63540780c79088b37a0c74 | https://github.com/Jacksgong/JKeyboardPanelSwitch/blob/092128023e824c85da63540780c79088b37a0c74/app/src/main/java/cn/dreamtobe/kpswitch/demo/activity/MainActivity.java#L93-L99 | train |
Jacksgong/JKeyboardPanelSwitch | library/src/main/java/cn/dreamtobe/kpswitch/util/KPSwitchConflictUtil.java | KPSwitchConflictUtil.hidePanelAndKeyboard | public static void hidePanelAndKeyboard(final View panelLayout) {
final Activity activity = (Activity) panelLayout.getContext();
final View focusView = activity.getCurrentFocus();
if (focusView != null) {
KeyboardUtil.hideKeyboard(activity.getCurrentFocus());
focusView.clearFocus();
}
panelLayout.setVisibility(View.GONE);
} | java | public static void hidePanelAndKeyboard(final View panelLayout) {
final Activity activity = (Activity) panelLayout.getContext();
final View focusView = activity.getCurrentFocus();
if (focusView != null) {
KeyboardUtil.hideKeyboard(activity.getCurrentFocus());
focusView.clearFocus();
}
panelLayout.setVisibility(View.GONE);
} | [
"public",
"static",
"void",
"hidePanelAndKeyboard",
"(",
"final",
"View",
"panelLayout",
")",
"{",
"final",
"Activity",
"activity",
"=",
"(",
"Activity",
")",
"panelLayout",
".",
"getContext",
"(",
")",
";",
"final",
"View",
"focusView",
"=",
"activity",
".",
... | Hide the panel and the keyboard.
@param panelLayout the layout of panel. | [
"Hide",
"the",
"panel",
"and",
"the",
"keyboard",
"."
] | 092128023e824c85da63540780c79088b37a0c74 | https://github.com/Jacksgong/JKeyboardPanelSwitch/blob/092128023e824c85da63540780c79088b37a0c74/library/src/main/java/cn/dreamtobe/kpswitch/util/KPSwitchConflictUtil.java#L243-L253 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/TypefaceProvider.java | TypefaceProvider.getTypeface | public static Typeface getTypeface(Context context, IconSet iconSet) {
String path = iconSet.fontPath().toString();
if (TYPEFACE_MAP.get(path) == null) {
final Typeface font = Typeface.createFromAsset(context.getAssets(), path);
TYPEFACE_MAP.put(path, font);
}
return TYPEFACE_MAP.get(path);
} | java | public static Typeface getTypeface(Context context, IconSet iconSet) {
String path = iconSet.fontPath().toString();
if (TYPEFACE_MAP.get(path) == null) {
final Typeface font = Typeface.createFromAsset(context.getAssets(), path);
TYPEFACE_MAP.put(path, font);
}
return TYPEFACE_MAP.get(path);
} | [
"public",
"static",
"Typeface",
"getTypeface",
"(",
"Context",
"context",
",",
"IconSet",
"iconSet",
")",
"{",
"String",
"path",
"=",
"iconSet",
".",
"fontPath",
"(",
")",
".",
"toString",
"(",
")",
";",
"if",
"(",
"TYPEFACE_MAP",
".",
"get",
"(",
"path"... | Returns a reference to the requested typeface, creating a new instance if none already exists
@param context the current context
@param iconSet the icon typeface
@return a reference to the typeface instance | [
"Returns",
"a",
"reference",
"to",
"the",
"requested",
"typeface",
"creating",
"a",
"new",
"instance",
"if",
"none",
"already",
"exists"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/TypefaceProvider.java#L31-L39 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/TypefaceProvider.java | TypefaceProvider.registerDefaultIconSets | public static void registerDefaultIconSets() {
final FontAwesome fontAwesome = new FontAwesome();
final Typicon typicon = new Typicon();
final MaterialIcons materialIcons = new MaterialIcons();
REGISTERED_ICON_SETS.put(fontAwesome.fontPath(), fontAwesome);
REGISTERED_ICON_SETS.put(typicon.fontPath(), typicon);
REGISTERED_ICON_SETS.put(materialIcons.fontPath(), materialIcons);
} | java | public static void registerDefaultIconSets() {
final FontAwesome fontAwesome = new FontAwesome();
final Typicon typicon = new Typicon();
final MaterialIcons materialIcons = new MaterialIcons();
REGISTERED_ICON_SETS.put(fontAwesome.fontPath(), fontAwesome);
REGISTERED_ICON_SETS.put(typicon.fontPath(), typicon);
REGISTERED_ICON_SETS.put(materialIcons.fontPath(), materialIcons);
} | [
"public",
"static",
"void",
"registerDefaultIconSets",
"(",
")",
"{",
"final",
"FontAwesome",
"fontAwesome",
"=",
"new",
"FontAwesome",
"(",
")",
";",
"final",
"Typicon",
"typicon",
"=",
"new",
"Typicon",
"(",
")",
";",
"final",
"MaterialIcons",
"materialIcons",... | Registers instances of the Default IconSets so that they are available throughout the whole
application. Currently the default icon sets include FontAwesome and Typicon. | [
"Registers",
"instances",
"of",
"the",
"Default",
"IconSets",
"so",
"that",
"they",
"are",
"available",
"throughout",
"the",
"whole",
"application",
".",
"Currently",
"the",
"default",
"icon",
"sets",
"include",
"FontAwesome",
"and",
"Typicon",
"."
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/TypefaceProvider.java#L45-L53 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/TypefaceProvider.java | TypefaceProvider.retrieveRegisteredIconSet | public static IconSet retrieveRegisteredIconSet(String fontPath, boolean editMode) {
final IconSet iconSet = REGISTERED_ICON_SETS.get(fontPath);
if (iconSet == null && !editMode) {
throw new RuntimeException(String.format("Font '%s' not properly registered, please" +
" see the README at https://github.com/Bearded-Hen/Android-Bootstrap", fontPath));
}
return iconSet;
} | java | public static IconSet retrieveRegisteredIconSet(String fontPath, boolean editMode) {
final IconSet iconSet = REGISTERED_ICON_SETS.get(fontPath);
if (iconSet == null && !editMode) {
throw new RuntimeException(String.format("Font '%s' not properly registered, please" +
" see the README at https://github.com/Bearded-Hen/Android-Bootstrap", fontPath));
}
return iconSet;
} | [
"public",
"static",
"IconSet",
"retrieveRegisteredIconSet",
"(",
"String",
"fontPath",
",",
"boolean",
"editMode",
")",
"{",
"final",
"IconSet",
"iconSet",
"=",
"REGISTERED_ICON_SETS",
".",
"get",
"(",
"fontPath",
")",
";",
"if",
"(",
"iconSet",
"==",
"null",
... | Retrieves a registered IconSet whose font can be found in the asset directory at the given path
@param fontPath the given path
@param editMode - whether the view requesting the icon set is displayed in the preview editor
@return the registered IconSet instance | [
"Retrieves",
"a",
"registered",
"IconSet",
"whose",
"font",
"can",
"be",
"found",
"in",
"the",
"asset",
"directory",
"at",
"the",
"given",
"path"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/TypefaceProvider.java#L71-L79 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapButtonGroup.java | BootstrapButtonGroup.onRadioToggle | void onRadioToggle(int index) {
for (int i = 0; i < getChildCount(); i++) {
if (i != index) {
BootstrapButton b = retrieveButtonChild(i);
b.setSelected(false);
}
}
} | java | void onRadioToggle(int index) {
for (int i = 0; i < getChildCount(); i++) {
if (i != index) {
BootstrapButton b = retrieveButtonChild(i);
b.setSelected(false);
}
}
} | [
"void",
"onRadioToggle",
"(",
"int",
"index",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"getChildCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"!=",
"index",
")",
"{",
"BootstrapButton",
"b",
"=",
"retrieveButtonChild... | Used for Radio Group Mode - resets all children to an unselected state,
apart from the calling Button.
@param index the index of the button becoming selected | [
"Used",
"for",
"Radio",
"Group",
"Mode",
"-",
"resets",
"all",
"children",
"to",
"an",
"unselected",
"state",
"apart",
"from",
"the",
"calling",
"Button",
"."
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapButtonGroup.java#L209-L217 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/AwesomeTextView.java | AwesomeTextView.startFlashing | public void startFlashing(boolean forever, AnimationSpeed speed) {
Animation fadeIn = new AlphaAnimation(0, 1);
//set up extra variables
fadeIn.setDuration(50);
fadeIn.setRepeatMode(Animation.REVERSE);
//default repeat count is 0, however if user wants, set it up to be infinite
fadeIn.setRepeatCount(0);
if (forever) {
fadeIn.setRepeatCount(Animation.INFINITE);
}
fadeIn.setStartOffset(speed.getFlashDuration());
startAnimation(fadeIn);
} | java | public void startFlashing(boolean forever, AnimationSpeed speed) {
Animation fadeIn = new AlphaAnimation(0, 1);
//set up extra variables
fadeIn.setDuration(50);
fadeIn.setRepeatMode(Animation.REVERSE);
//default repeat count is 0, however if user wants, set it up to be infinite
fadeIn.setRepeatCount(0);
if (forever) {
fadeIn.setRepeatCount(Animation.INFINITE);
}
fadeIn.setStartOffset(speed.getFlashDuration());
startAnimation(fadeIn);
} | [
"public",
"void",
"startFlashing",
"(",
"boolean",
"forever",
",",
"AnimationSpeed",
"speed",
")",
"{",
"Animation",
"fadeIn",
"=",
"new",
"AlphaAnimation",
"(",
"0",
",",
"1",
")",
";",
"//set up extra variables",
"fadeIn",
".",
"setDuration",
"(",
"50",
")",... | Starts a Flashing Animation on the AwesomeTextView
@param forever whether the animation should be infinite or play once
@param speed how fast the item should flash | [
"Starts",
"a",
"Flashing",
"Animation",
"on",
"the",
"AwesomeTextView"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/AwesomeTextView.java#L163-L178 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/AwesomeTextView.java | AwesomeTextView.startRotate | public void startRotate(boolean clockwise, AnimationSpeed speed) {
Animation rotate;
//set up the rotation animation
if (clockwise) {
rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else {
rotate = new RotateAnimation(360, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
//set up some extra variables
rotate.setRepeatCount(Animation.INFINITE);
rotate.setInterpolator(new LinearInterpolator());
rotate.setStartOffset(0);
rotate.setRepeatMode(Animation.RESTART);
rotate.setDuration(speed.getRotateDuration());
startAnimation(rotate);
} | java | public void startRotate(boolean clockwise, AnimationSpeed speed) {
Animation rotate;
//set up the rotation animation
if (clockwise) {
rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
else {
rotate = new RotateAnimation(360, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
}
//set up some extra variables
rotate.setRepeatCount(Animation.INFINITE);
rotate.setInterpolator(new LinearInterpolator());
rotate.setStartOffset(0);
rotate.setRepeatMode(Animation.RESTART);
rotate.setDuration(speed.getRotateDuration());
startAnimation(rotate);
} | [
"public",
"void",
"startRotate",
"(",
"boolean",
"clockwise",
",",
"AnimationSpeed",
"speed",
")",
"{",
"Animation",
"rotate",
";",
"//set up the rotation animation",
"if",
"(",
"clockwise",
")",
"{",
"rotate",
"=",
"new",
"RotateAnimation",
"(",
"0",
",",
"360"... | Starts a rotating animation on the AwesomeTextView
@param clockwise true for clockwise, false for anti clockwise spinning
@param speed how fast the item should rotate | [
"Starts",
"a",
"rotating",
"animation",
"on",
"the",
"AwesomeTextView"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/AwesomeTextView.java#L186-L204 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/IconResolver.java | IconResolver.resolveIconSet | private static IconSet resolveIconSet(String iconCode) {
CharSequence unicode;
for (IconSet set : getRegisteredIconSets()) {
if (set.fontPath().equals(FontAwesome.FONT_PATH) || set.fontPath().equals(Typicon.FONT_PATH) || set.fontPath().equals(MaterialIcons.FONT_PATH)) {
continue; // already checked previously, ignore
}
unicode = set.unicodeForKey(iconCode);
if (unicode != null) {
return set;
}
}
String message = String.format("Could not find FontIcon value for '%s', " +
"please ensure that it is mapped to a valid font", iconCode);
throw new IllegalArgumentException(message);
} | java | private static IconSet resolveIconSet(String iconCode) {
CharSequence unicode;
for (IconSet set : getRegisteredIconSets()) {
if (set.fontPath().equals(FontAwesome.FONT_PATH) || set.fontPath().equals(Typicon.FONT_PATH) || set.fontPath().equals(MaterialIcons.FONT_PATH)) {
continue; // already checked previously, ignore
}
unicode = set.unicodeForKey(iconCode);
if (unicode != null) {
return set;
}
}
String message = String.format("Could not find FontIcon value for '%s', " +
"please ensure that it is mapped to a valid font", iconCode);
throw new IllegalArgumentException(message);
} | [
"private",
"static",
"IconSet",
"resolveIconSet",
"(",
"String",
"iconCode",
")",
"{",
"CharSequence",
"unicode",
";",
"for",
"(",
"IconSet",
"set",
":",
"getRegisteredIconSets",
"(",
")",
")",
"{",
"if",
"(",
"set",
".",
"fontPath",
"(",
")",
".",
"equals... | Searches for the unicode character value for the Font Icon Code. This method searches all
active FontIcons in the application.
@param iconCode the font icon code
@return the unicode character matching the icon, or null if none matches | [
"Searches",
"for",
"the",
"unicode",
"character",
"value",
"for",
"the",
"Font",
"Icon",
"Code",
".",
"This",
"method",
"searches",
"all",
"active",
"FontIcons",
"in",
"the",
"application",
"."
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/IconResolver.java#L112-L132 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDropDown.java | BootstrapDropDown.measureStringWidth | private float measureStringWidth(String text) {
Paint mPaint = new Paint();
mPaint.setTextSize(baselineDropDownViewFontSize * bootstrapSize);
return (float) (DimenUtils.dpToPixels(mPaint.measureText(text)));
} | java | private float measureStringWidth(String text) {
Paint mPaint = new Paint();
mPaint.setTextSize(baselineDropDownViewFontSize * bootstrapSize);
return (float) (DimenUtils.dpToPixels(mPaint.measureText(text)));
} | [
"private",
"float",
"measureStringWidth",
"(",
"String",
"text",
")",
"{",
"Paint",
"mPaint",
"=",
"new",
"Paint",
"(",
")",
";",
"mPaint",
".",
"setTextSize",
"(",
"baselineDropDownViewFontSize",
"*",
"bootstrapSize",
")",
";",
"return",
"(",
"float",
")",
... | Calculating string width
@param text String to calculate
@return width of String in pixels | [
"Calculating",
"string",
"width"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDropDown.java#L291-L295 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDropDown.java | BootstrapDropDown.getLongestString | private String getLongestString(String[] array) {
int maxLength = 0;
String longestString = null;
for (String s : array) {
if (s.length() > maxLength) {
maxLength = s.length();
longestString = s;
}
}
return longestString;
} | java | private String getLongestString(String[] array) {
int maxLength = 0;
String longestString = null;
for (String s : array) {
if (s.length() > maxLength) {
maxLength = s.length();
longestString = s;
}
}
return longestString;
} | [
"private",
"String",
"getLongestString",
"(",
"String",
"[",
"]",
"array",
")",
"{",
"int",
"maxLength",
"=",
"0",
";",
"String",
"longestString",
"=",
"null",
";",
"for",
"(",
"String",
"s",
":",
"array",
")",
"{",
"if",
"(",
"s",
".",
"length",
"("... | Searching for longest string in array
@param array input string array
@return longest string | [
"Searching",
"for",
"longest",
"string",
"in",
"array"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDropDown.java#L304-L314 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBarGroup.java | BootstrapProgressBarGroup.addEmptyProgressBar | private void addEmptyProgressBar(){
int whereIsEmpty = -1;
for (int i = 0; i < getChildCount(); i++) {
if (retrieveChild(i) != null && retrieveChild(i).equals(emptyProgressBar)) {
whereIsEmpty = i;
}
}
if (whereIsEmpty != getChildCount() - 1) {
if (whereIsEmpty != -1) {
//the flowing true/false is to stop empty progressbar being added more than once as removeView and addView indirectly call this method
isEmptyBeingAdded = true;
removeView(emptyProgressBar);
isEmptyBeingAdded = false;
}
if (!isEmptyBeingAdded) {
addView(emptyProgressBar);
}
}
} | java | private void addEmptyProgressBar(){
int whereIsEmpty = -1;
for (int i = 0; i < getChildCount(); i++) {
if (retrieveChild(i) != null && retrieveChild(i).equals(emptyProgressBar)) {
whereIsEmpty = i;
}
}
if (whereIsEmpty != getChildCount() - 1) {
if (whereIsEmpty != -1) {
//the flowing true/false is to stop empty progressbar being added more than once as removeView and addView indirectly call this method
isEmptyBeingAdded = true;
removeView(emptyProgressBar);
isEmptyBeingAdded = false;
}
if (!isEmptyBeingAdded) {
addView(emptyProgressBar);
}
}
} | [
"private",
"void",
"addEmptyProgressBar",
"(",
")",
"{",
"int",
"whereIsEmpty",
"=",
"-",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"getChildCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"retrieveChild",
"(",
"i",
")",
"... | This looks for instances of emptyProgressBar and removes them if they are not at the end and then adds one at the end if its needed. | [
"This",
"looks",
"for",
"instances",
"of",
"emptyProgressBar",
"and",
"removes",
"them",
"if",
"they",
"are",
"not",
"at",
"the",
"end",
"and",
"then",
"adds",
"one",
"at",
"the",
"end",
"if",
"its",
"needed",
"."
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBarGroup.java#L80-L99 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBarGroup.java | BootstrapProgressBarGroup.getCumulativeProgress | public int getCumulativeProgress(){
int numChildren = getChildCount();
int total = 0;
for (int i = 0; i < numChildren; i++) {
total += getChildProgress(i);
}
checkCumulativeSmallerThanMax(maxProgress, total);
return total;
} | java | public int getCumulativeProgress(){
int numChildren = getChildCount();
int total = 0;
for (int i = 0; i < numChildren; i++) {
total += getChildProgress(i);
}
checkCumulativeSmallerThanMax(maxProgress, total);
return total;
} | [
"public",
"int",
"getCumulativeProgress",
"(",
")",
"{",
"int",
"numChildren",
"=",
"getChildCount",
"(",
")",
";",
"int",
"total",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numChildren",
";",
"i",
"++",
")",
"{",
"total",
"+... | This get the total progress of all the children
@return the CumulativeProgress i.e. the total progress of all children | [
"This",
"get",
"the",
"total",
"progress",
"of",
"all",
"the",
"children"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBarGroup.java#L146-L154 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBarGroup.java | BootstrapProgressBarGroup.setStriped | @Override
public void setStriped(boolean striped) {
this.striped = striped;
for (int i = 0; i < getChildCount(); i++) {
retrieveChild(i).setStriped(striped);
}
} | java | @Override
public void setStriped(boolean striped) {
this.striped = striped;
for (int i = 0; i < getChildCount(); i++) {
retrieveChild(i).setStriped(striped);
}
} | [
"@",
"Override",
"public",
"void",
"setStriped",
"(",
"boolean",
"striped",
")",
"{",
"this",
".",
"striped",
"=",
"striped",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"getChildCount",
"(",
")",
";",
"i",
"++",
")",
"{",
"retrieveChild",
... | This will set all children to striped.
@param striped true for a striped pattern, false for a plain pattern | [
"This",
"will",
"set",
"all",
"children",
"to",
"striped",
"."
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBarGroup.java#L246-L252 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java | BootstrapDrawableFactory.bootstrapButton | static Drawable bootstrapButton(Context context,
BootstrapBrand brand,
int strokeWidth,
int cornerRadius,
ViewGroupPosition position,
boolean showOutline,
boolean rounded) {
GradientDrawable defaultGd = new GradientDrawable();
GradientDrawable activeGd = new GradientDrawable();
GradientDrawable disabledGd = new GradientDrawable();
defaultGd.setColor(showOutline ? Color.TRANSPARENT : brand.defaultFill(context));
activeGd.setColor(showOutline ? brand.activeFill(context) : brand.activeFill(context));
disabledGd.setColor(showOutline ? Color.TRANSPARENT : brand.disabledFill(context));
defaultGd.setStroke(strokeWidth, brand.defaultEdge(context));
activeGd.setStroke(strokeWidth, brand.activeEdge(context));
disabledGd.setStroke(strokeWidth, brand.disabledEdge(context));
if (showOutline && brand instanceof DefaultBootstrapBrand) {
DefaultBootstrapBrand db = (DefaultBootstrapBrand) brand;
if (db == DefaultBootstrapBrand.SECONDARY) {
int color = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
defaultGd.setStroke(strokeWidth, color);
activeGd.setStroke(strokeWidth, color);
disabledGd.setStroke(strokeWidth, color);
}
}
setupDrawableCorners(position, rounded, cornerRadius, defaultGd, activeGd, disabledGd);
return setupStateDrawable(position, strokeWidth, defaultGd, activeGd, disabledGd);
} | java | static Drawable bootstrapButton(Context context,
BootstrapBrand brand,
int strokeWidth,
int cornerRadius,
ViewGroupPosition position,
boolean showOutline,
boolean rounded) {
GradientDrawable defaultGd = new GradientDrawable();
GradientDrawable activeGd = new GradientDrawable();
GradientDrawable disabledGd = new GradientDrawable();
defaultGd.setColor(showOutline ? Color.TRANSPARENT : brand.defaultFill(context));
activeGd.setColor(showOutline ? brand.activeFill(context) : brand.activeFill(context));
disabledGd.setColor(showOutline ? Color.TRANSPARENT : brand.disabledFill(context));
defaultGd.setStroke(strokeWidth, brand.defaultEdge(context));
activeGd.setStroke(strokeWidth, brand.activeEdge(context));
disabledGd.setStroke(strokeWidth, brand.disabledEdge(context));
if (showOutline && brand instanceof DefaultBootstrapBrand) {
DefaultBootstrapBrand db = (DefaultBootstrapBrand) brand;
if (db == DefaultBootstrapBrand.SECONDARY) {
int color = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
defaultGd.setStroke(strokeWidth, color);
activeGd.setStroke(strokeWidth, color);
disabledGd.setStroke(strokeWidth, color);
}
}
setupDrawableCorners(position, rounded, cornerRadius, defaultGd, activeGd, disabledGd);
return setupStateDrawable(position, strokeWidth, defaultGd, activeGd, disabledGd);
} | [
"static",
"Drawable",
"bootstrapButton",
"(",
"Context",
"context",
",",
"BootstrapBrand",
"brand",
",",
"int",
"strokeWidth",
",",
"int",
"cornerRadius",
",",
"ViewGroupPosition",
"position",
",",
"boolean",
"showOutline",
",",
"boolean",
"rounded",
")",
"{",
"Gr... | Generates a background drawable for a Bootstrap Button
@param context the current context
@param brand the bootstrap brand
@param strokeWidth the stroke width in px
@param cornerRadius the corner radius in px
@param position the position of the button in its parent view
@param showOutline whether the button should be outlined
@param rounded whether the corners should be rounded
@return a background drawable for the BootstrapButton | [
"Generates",
"a",
"background",
"drawable",
"for",
"a",
"Bootstrap",
"Button"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java#L45-L79 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java | BootstrapDrawableFactory.bootstrapLabel | static Drawable bootstrapLabel(Context context,
BootstrapBrand bootstrapBrand,
boolean rounded,
float height) {
int cornerRadius = (int) DimenUtils.pixelsFromDpResource(context, R.dimen.bootstrap_default_corner_radius);
GradientDrawable drawable = new GradientDrawable();
drawable.setColor(bootstrapBrand.defaultFill(context));
// corner radius should be half height if rounded as a "Pill" label
drawable.setCornerRadius(rounded ? height / 2 : cornerRadius);
return drawable;
} | java | static Drawable bootstrapLabel(Context context,
BootstrapBrand bootstrapBrand,
boolean rounded,
float height) {
int cornerRadius = (int) DimenUtils.pixelsFromDpResource(context, R.dimen.bootstrap_default_corner_radius);
GradientDrawable drawable = new GradientDrawable();
drawable.setColor(bootstrapBrand.defaultFill(context));
// corner radius should be half height if rounded as a "Pill" label
drawable.setCornerRadius(rounded ? height / 2 : cornerRadius);
return drawable;
} | [
"static",
"Drawable",
"bootstrapLabel",
"(",
"Context",
"context",
",",
"BootstrapBrand",
"bootstrapBrand",
",",
"boolean",
"rounded",
",",
"float",
"height",
")",
"{",
"int",
"cornerRadius",
"=",
"(",
"int",
")",
"DimenUtils",
".",
"pixelsFromDpResource",
"(",
... | Generates a Drawable for a Bootstrap Label background, according to state parameters
@param context the current context
@param bootstrapBrand the BootstrapBrand theming whose colors should be used
@param rounded whether the corners should be rounded or not
@param height the view height in px
@return the Bootstrap Label background | [
"Generates",
"a",
"Drawable",
"for",
"a",
"Bootstrap",
"Label",
"background",
"according",
"to",
"state",
"parameters"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java#L90-L103 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java | BootstrapDrawableFactory.bootstrapEditText | static Drawable bootstrapEditText(Context context,
BootstrapBrand bootstrapBrand,
float strokeWidth,
float cornerRadius,
boolean rounded) {
StateListDrawable drawable = new StateListDrawable();
GradientDrawable activeDrawable = new GradientDrawable();
GradientDrawable disabledDrawable = new GradientDrawable();
GradientDrawable defaultDrawable = new GradientDrawable();
activeDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
disabledDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
defaultDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
if (rounded) {
activeDrawable.setCornerRadius(cornerRadius);
disabledDrawable.setCornerRadius(cornerRadius);
defaultDrawable.setCornerRadius(cornerRadius);
}
// stroke is larger when focused
int defaultBorder = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
int disabledBorder = ColorUtils.resolveColor(R.color.bootstrap_edittext_disabled, context);
activeDrawable.setStroke((int) strokeWidth, bootstrapBrand.defaultEdge(context));
disabledDrawable.setStroke((int) strokeWidth, disabledBorder);
defaultDrawable.setStroke((int) strokeWidth, defaultBorder);
drawable.addState(new int[]{android.R.attr.state_focused}, activeDrawable);
drawable.addState(new int[]{-android.R.attr.state_enabled}, disabledDrawable);
drawable.addState(new int[]{}, defaultDrawable);
return drawable;
} | java | static Drawable bootstrapEditText(Context context,
BootstrapBrand bootstrapBrand,
float strokeWidth,
float cornerRadius,
boolean rounded) {
StateListDrawable drawable = new StateListDrawable();
GradientDrawable activeDrawable = new GradientDrawable();
GradientDrawable disabledDrawable = new GradientDrawable();
GradientDrawable defaultDrawable = new GradientDrawable();
activeDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
disabledDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
defaultDrawable.setColor(ColorUtils.resolveColor(android.R.color.white, context));
if (rounded) {
activeDrawable.setCornerRadius(cornerRadius);
disabledDrawable.setCornerRadius(cornerRadius);
defaultDrawable.setCornerRadius(cornerRadius);
}
// stroke is larger when focused
int defaultBorder = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
int disabledBorder = ColorUtils.resolveColor(R.color.bootstrap_edittext_disabled, context);
activeDrawable.setStroke((int) strokeWidth, bootstrapBrand.defaultEdge(context));
disabledDrawable.setStroke((int) strokeWidth, disabledBorder);
defaultDrawable.setStroke((int) strokeWidth, defaultBorder);
drawable.addState(new int[]{android.R.attr.state_focused}, activeDrawable);
drawable.addState(new int[]{-android.R.attr.state_enabled}, disabledDrawable);
drawable.addState(new int[]{}, defaultDrawable);
return drawable;
} | [
"static",
"Drawable",
"bootstrapEditText",
"(",
"Context",
"context",
",",
"BootstrapBrand",
"bootstrapBrand",
",",
"float",
"strokeWidth",
",",
"float",
"cornerRadius",
",",
"boolean",
"rounded",
")",
"{",
"StateListDrawable",
"drawable",
"=",
"new",
"StateListDrawab... | Generates a Drawable for a Bootstrap Edit Text background
@param context the current context
@param bootstrapBrand the BootstrapBrand theming whose colors should be used
@param rounded whether the corners should be rounded or not
@return the Bootstrap Edit Text background | [
"Generates",
"a",
"Drawable",
"for",
"a",
"Bootstrap",
"Edit",
"Text",
"background"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java#L113-L148 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java | BootstrapDrawableFactory.bootstrapButtonText | static ColorStateList bootstrapButtonText(Context context, boolean outline, BootstrapBrand brand) {
int defaultColor = outline ? brand.defaultFill(context) : brand.defaultTextColor(context);
int activeColor = outline ? ColorUtils.resolveColor(android.R.color.white, context) : brand.activeTextColor(context);
int disabledColor = outline ? brand.disabledFill(context) : brand.disabledTextColor(context);
if (outline && brand instanceof DefaultBootstrapBrand) { // special case
DefaultBootstrapBrand db = (DefaultBootstrapBrand) brand;
if (db == DefaultBootstrapBrand.SECONDARY) {
defaultColor = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
disabledColor = defaultColor;
}
}
return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
} | java | static ColorStateList bootstrapButtonText(Context context, boolean outline, BootstrapBrand brand) {
int defaultColor = outline ? brand.defaultFill(context) : brand.defaultTextColor(context);
int activeColor = outline ? ColorUtils.resolveColor(android.R.color.white, context) : brand.activeTextColor(context);
int disabledColor = outline ? brand.disabledFill(context) : brand.disabledTextColor(context);
if (outline && brand instanceof DefaultBootstrapBrand) { // special case
DefaultBootstrapBrand db = (DefaultBootstrapBrand) brand;
if (db == DefaultBootstrapBrand.SECONDARY) {
defaultColor = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
disabledColor = defaultColor;
}
}
return new ColorStateList(getStateList(), getColorList(defaultColor, activeColor, disabledColor));
} | [
"static",
"ColorStateList",
"bootstrapButtonText",
"(",
"Context",
"context",
",",
"boolean",
"outline",
",",
"BootstrapBrand",
"brand",
")",
"{",
"int",
"defaultColor",
"=",
"outline",
"?",
"brand",
".",
"defaultFill",
"(",
"context",
")",
":",
"brand",
".",
... | Generates a colorstatelist for a bootstrap button
@param context the current context
@param outline whether the button is outlined
@param brand the button brand
@return the color state list | [
"Generates",
"a",
"colorstatelist",
"for",
"a",
"bootstrap",
"button"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java#L204-L219 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java | BootstrapDrawableFactory.createArrowIcon | private static Drawable createArrowIcon(Context context, int width, int height, int color, ExpandDirection expandDirection) {
Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(canvasBitmap);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(1);
paint.setColor(color);
paint.setAntiAlias(true);
Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
switch (expandDirection) {
case UP:
path.moveTo(0, (height / 3) * 2);
path.lineTo(width, (height / 3) * 2);
path.lineTo(width / 2, height / 3);
path.lineTo(0, (height / 3) * 2);
break;
case DOWN:
path.moveTo(0, height / 3);
path.lineTo(width, height / 3);
path.lineTo(width / 2, (height / 3) * 2);
path.lineTo(0, height / 3);
break;
}
path.close();
canvas.drawPath(path, paint);
return new BitmapDrawable(context.getResources(), canvasBitmap);
} | java | private static Drawable createArrowIcon(Context context, int width, int height, int color, ExpandDirection expandDirection) {
Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(canvasBitmap);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(1);
paint.setColor(color);
paint.setAntiAlias(true);
Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
switch (expandDirection) {
case UP:
path.moveTo(0, (height / 3) * 2);
path.lineTo(width, (height / 3) * 2);
path.lineTo(width / 2, height / 3);
path.lineTo(0, (height / 3) * 2);
break;
case DOWN:
path.moveTo(0, height / 3);
path.lineTo(width, height / 3);
path.lineTo(width / 2, (height / 3) * 2);
path.lineTo(0, height / 3);
break;
}
path.close();
canvas.drawPath(path, paint);
return new BitmapDrawable(context.getResources(), canvasBitmap);
} | [
"private",
"static",
"Drawable",
"createArrowIcon",
"(",
"Context",
"context",
",",
"int",
"width",
",",
"int",
"height",
",",
"int",
"color",
",",
"ExpandDirection",
"expandDirection",
")",
"{",
"Bitmap",
"canvasBitmap",
"=",
"Bitmap",
".",
"createBitmap",
"(",... | Creates arrow icon that depends on ExpandDirection
@param context context
@param width width of icon in pixels
@param height height of icon in pixels
@param color arrow color
@param expandDirection arrow direction
@return icon drawable | [
"Creates",
"arrow",
"icon",
"that",
"depends",
"on",
"ExpandDirection"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapDrawableFactory.java#L390-L417 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBar.java | BootstrapProgressBar.startStripedAnimationIfNeeded | private void startStripedAnimationIfNeeded() {
if (!striped || !animated) {
return;
}
clearAnimation();
progressAnimator = ValueAnimator.ofFloat(0, 0);
progressAnimator.setDuration(UPDATE_ANIM_MS);
progressAnimator.setRepeatCount(ValueAnimator.INFINITE);
progressAnimator.setRepeatMode(ValueAnimator.RESTART);
progressAnimator.setInterpolator(new LinearInterpolator());
progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
invalidate();
}
});
progressAnimator.start();
} | java | private void startStripedAnimationIfNeeded() {
if (!striped || !animated) {
return;
}
clearAnimation();
progressAnimator = ValueAnimator.ofFloat(0, 0);
progressAnimator.setDuration(UPDATE_ANIM_MS);
progressAnimator.setRepeatCount(ValueAnimator.INFINITE);
progressAnimator.setRepeatMode(ValueAnimator.RESTART);
progressAnimator.setInterpolator(new LinearInterpolator());
progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
invalidate();
}
});
progressAnimator.start();
} | [
"private",
"void",
"startStripedAnimationIfNeeded",
"(",
")",
"{",
"if",
"(",
"!",
"striped",
"||",
"!",
"animated",
")",
"{",
"return",
";",
"}",
"clearAnimation",
"(",
")",
";",
"progressAnimator",
"=",
"ValueAnimator",
".",
"ofFloat",
"(",
"0",
",",
"0"... | Starts an infinite animation cycle which provides the visual effect of stripes moving
backwards. The current system time is used to offset tiled bitmaps of the progress background,
producing the effect that the stripes are moving backwards. | [
"Starts",
"an",
"infinite",
"animation",
"cycle",
"which",
"provides",
"the",
"visual",
"effect",
"of",
"stripes",
"moving",
"backwards",
".",
"The",
"current",
"system",
"time",
"is",
"used",
"to",
"offset",
"tiled",
"bitmaps",
"of",
"the",
"progress",
"backg... | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBar.java#L250-L270 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBar.java | BootstrapProgressBar.createTile | private static Bitmap createTile(float h, Paint stripePaint, Paint progressPaint) {
Bitmap bm = Bitmap.createBitmap((int) h * 2, (int) h, ARGB_8888);
Canvas tile = new Canvas(bm);
float x = 0;
Path path = new Path();
path.moveTo(x, 0);
path.lineTo(x, h);
path.lineTo(h, h);
tile.drawPath(path, stripePaint); // draw striped triangle
path.reset();
path.moveTo(x, 0);
path.lineTo(x + h, h);
path.lineTo(x + (h * 2), h);
path.lineTo(x + h, 0);
tile.drawPath(path, progressPaint); // draw progress parallelogram
x += h;
path.reset();
path.moveTo(x, 0);
path.lineTo(x + h, 0);
path.lineTo(x + h, h);
tile.drawPath(path, stripePaint); // draw striped triangle (completing tile)
return bm;
} | java | private static Bitmap createTile(float h, Paint stripePaint, Paint progressPaint) {
Bitmap bm = Bitmap.createBitmap((int) h * 2, (int) h, ARGB_8888);
Canvas tile = new Canvas(bm);
float x = 0;
Path path = new Path();
path.moveTo(x, 0);
path.lineTo(x, h);
path.lineTo(h, h);
tile.drawPath(path, stripePaint); // draw striped triangle
path.reset();
path.moveTo(x, 0);
path.lineTo(x + h, h);
path.lineTo(x + (h * 2), h);
path.lineTo(x + h, 0);
tile.drawPath(path, progressPaint); // draw progress parallelogram
x += h;
path.reset();
path.moveTo(x, 0);
path.lineTo(x + h, 0);
path.lineTo(x + h, h);
tile.drawPath(path, stripePaint); // draw striped triangle (completing tile)
return bm;
} | [
"private",
"static",
"Bitmap",
"createTile",
"(",
"float",
"h",
",",
"Paint",
"stripePaint",
",",
"Paint",
"progressPaint",
")",
"{",
"Bitmap",
"bm",
"=",
"Bitmap",
".",
"createBitmap",
"(",
"(",
"int",
")",
"h",
"*",
"2",
",",
"(",
"int",
")",
"h",
... | Creates a Bitmap which is a tile of the progress bar background
@param h the view height
@return a bitmap of the progress bar background | [
"Creates",
"a",
"Bitmap",
"which",
"is",
"a",
"tile",
"of",
"the",
"progress",
"bar",
"background"
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBar.java#L374-L401 | train |
Bearded-Hen/Android-Bootstrap | AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBar.java | BootstrapProgressBar.setMaxProgress | public void setMaxProgress(int newMaxProgress) {
if (getProgress() <= newMaxProgress) {
maxProgress = newMaxProgress;
}
else {
throw new IllegalArgumentException(
String.format("MaxProgress cant be smaller than the current progress %d<%d", getProgress(), newMaxProgress));
}
invalidate();
BootstrapProgressBarGroup parent = (BootstrapProgressBarGroup) getParent();
} | java | public void setMaxProgress(int newMaxProgress) {
if (getProgress() <= newMaxProgress) {
maxProgress = newMaxProgress;
}
else {
throw new IllegalArgumentException(
String.format("MaxProgress cant be smaller than the current progress %d<%d", getProgress(), newMaxProgress));
}
invalidate();
BootstrapProgressBarGroup parent = (BootstrapProgressBarGroup) getParent();
} | [
"public",
"void",
"setMaxProgress",
"(",
"int",
"newMaxProgress",
")",
"{",
"if",
"(",
"getProgress",
"(",
")",
"<=",
"newMaxProgress",
")",
"{",
"maxProgress",
"=",
"newMaxProgress",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"Str... | Used for settings the maxprogress. Also check if currentProgress is smaller than newMaxProgress.
@param newMaxProgress the maxProgress value | [
"Used",
"for",
"settings",
"the",
"maxprogress",
".",
"Also",
"check",
"if",
"currentProgress",
"is",
"smaller",
"than",
"newMaxProgress",
"."
] | b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf | https://github.com/Bearded-Hen/Android-Bootstrap/blob/b3d62cc1847e26d420c53c92665a4fe1e6ee7ecf/AndroidBootstrap/src/main/java/com/beardedhen/androidbootstrap/BootstrapProgressBar.java#L582-L592 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcMultiServer.java | JsonRpcMultiServer.getHandlerInterfaces | @Override
protected Class<?>[] getHandlerInterfaces(String serviceName) {
Class<?> remoteInterface = interfaceMap.get(serviceName);
if (remoteInterface != null) {
return new Class<?>[]{remoteInterface};
} else if (Proxy.isProxyClass(getHandler(serviceName).getClass())) {
return getHandler(serviceName).getClass().getInterfaces();
} else {
return new Class<?>[]{getHandler(serviceName).getClass()};
}
} | java | @Override
protected Class<?>[] getHandlerInterfaces(String serviceName) {
Class<?> remoteInterface = interfaceMap.get(serviceName);
if (remoteInterface != null) {
return new Class<?>[]{remoteInterface};
} else if (Proxy.isProxyClass(getHandler(serviceName).getClass())) {
return getHandler(serviceName).getClass().getInterfaces();
} else {
return new Class<?>[]{getHandler(serviceName).getClass()};
}
} | [
"@",
"Override",
"protected",
"Class",
"<",
"?",
">",
"[",
"]",
"getHandlerInterfaces",
"(",
"String",
"serviceName",
")",
"{",
"Class",
"<",
"?",
">",
"remoteInterface",
"=",
"interfaceMap",
".",
"get",
"(",
"serviceName",
")",
";",
"if",
"(",
"remoteInte... | Returns the handler's class or interfaces. The serviceName is used
to look up a registered handler.
@param serviceName the optional name of a service
@return the class | [
"Returns",
"the",
"handler",
"s",
"class",
"or",
"interfaces",
".",
"The",
"serviceName",
"is",
"used",
"to",
"look",
"up",
"a",
"registered",
"handler",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcMultiServer.java#L88-L98 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcMultiServer.java | JsonRpcMultiServer.getServiceName | @Override
protected String getServiceName(final String methodName) {
if (methodName != null) {
int ndx = methodName.indexOf(this.separator);
if (ndx > 0) {
return methodName.substring(0, ndx);
}
}
return methodName;
} | java | @Override
protected String getServiceName(final String methodName) {
if (methodName != null) {
int ndx = methodName.indexOf(this.separator);
if (ndx > 0) {
return methodName.substring(0, ndx);
}
}
return methodName;
} | [
"@",
"Override",
"protected",
"String",
"getServiceName",
"(",
"final",
"String",
"methodName",
")",
"{",
"if",
"(",
"methodName",
"!=",
"null",
")",
"{",
"int",
"ndx",
"=",
"methodName",
".",
"indexOf",
"(",
"this",
".",
"separator",
")",
";",
"if",
"("... | Get the service name from the methodNode. JSON-RPC methods with the form
Service.method will result in "Service" being returned in this case.
@param methodName method name
@return the name of the service, or <code>null</code> | [
"Get",
"the",
"service",
"name",
"from",
"the",
"methodNode",
".",
"JSON",
"-",
"RPC",
"methods",
"with",
"the",
"form",
"Service",
".",
"method",
"will",
"result",
"in",
"Service",
"being",
"returned",
"in",
"this",
"case",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcMultiServer.java#L107-L116 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcServer.java | JsonRpcServer.handle | public void handle(ResourceRequest request, ResourceResponse response) throws IOException {
logger.debug("Handing ResourceRequest {}", request.getMethod());
response.setContentType(contentType);
InputStream input = getRequestStream(request);
OutputStream output = response.getPortletOutputStream();
handleRequest(input, output);
// fix to not flush within handleRequest() but outside so http status code can be set
output.flush();
} | java | public void handle(ResourceRequest request, ResourceResponse response) throws IOException {
logger.debug("Handing ResourceRequest {}", request.getMethod());
response.setContentType(contentType);
InputStream input = getRequestStream(request);
OutputStream output = response.getPortletOutputStream();
handleRequest(input, output);
// fix to not flush within handleRequest() but outside so http status code can be set
output.flush();
} | [
"public",
"void",
"handle",
"(",
"ResourceRequest",
"request",
",",
"ResourceResponse",
"response",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"Handing ResourceRequest {}\"",
",",
"request",
".",
"getMethod",
"(",
")",
")",
";",
"response",
... | Handles a portlet request.
@param request the {@link ResourceRequest}
@param response the {@link ResourceResponse}
@throws IOException on error | [
"Handles",
"a",
"portlet",
"request",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcServer.java#L103-L111 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcServer.java | JsonRpcServer.handle | public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.debug("Handling HttpServletRequest {}", request);
response.setContentType(contentType);
OutputStream output = response.getOutputStream();
InputStream input = getRequestStream(request);
int result = ErrorResolver.JsonError.PARSE_ERROR.code;
int contentLength = 0;
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
try {
String acceptEncoding = request.getHeader(ACCEPT_ENCODING);
result = handleRequest0(input, output, acceptEncoding, response, byteOutput);
contentLength = byteOutput.size();
} catch (Throwable t) {
if (StreamEndedException.class.isInstance(t)) {
logger.debug("Bad request: empty contents!");
} else {
logger.error(t.getMessage(), t);
}
}
int httpStatusCode = httpStatusCodeProvider == null ? DefaultHttpStatusCodeProvider.INSTANCE.getHttpStatusCode(result)
: httpStatusCodeProvider.getHttpStatusCode(result);
response.setStatus(httpStatusCode);
response.setContentLength(contentLength);
byteOutput.writeTo(output);
output.flush();
} | java | public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.debug("Handling HttpServletRequest {}", request);
response.setContentType(contentType);
OutputStream output = response.getOutputStream();
InputStream input = getRequestStream(request);
int result = ErrorResolver.JsonError.PARSE_ERROR.code;
int contentLength = 0;
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
try {
String acceptEncoding = request.getHeader(ACCEPT_ENCODING);
result = handleRequest0(input, output, acceptEncoding, response, byteOutput);
contentLength = byteOutput.size();
} catch (Throwable t) {
if (StreamEndedException.class.isInstance(t)) {
logger.debug("Bad request: empty contents!");
} else {
logger.error(t.getMessage(), t);
}
}
int httpStatusCode = httpStatusCodeProvider == null ? DefaultHttpStatusCodeProvider.INSTANCE.getHttpStatusCode(result)
: httpStatusCodeProvider.getHttpStatusCode(result);
response.setStatus(httpStatusCode);
response.setContentLength(contentLength);
byteOutput.writeTo(output);
output.flush();
} | [
"public",
"void",
"handle",
"(",
"HttpServletRequest",
"request",
",",
"HttpServletResponse",
"response",
")",
"throws",
"IOException",
"{",
"logger",
".",
"debug",
"(",
"\"Handling HttpServletRequest {}\"",
",",
"request",
")",
";",
"response",
".",
"setContentType",... | Handles a servlet request.
@param request the {@link HttpServletRequest}
@param response the {@link HttpServletResponse}
@throws IOException on error | [
"Handles",
"a",
"servlet",
"request",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcServer.java#L134-L160 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/StreamServer.java | StreamServer.stop | public void stop() throws InterruptedException {
if (!isStarted.get()) {
throw new IllegalStateException("The StreamServer is not started");
}
stopServer();
stopClients();
closeSocket();
try {
waitForServerToTerminate();
isStarted.set(false);
stopServer();
} catch (InterruptedException e) {
logger.error("InterruptedException while waiting for termination", e);
throw e;
}
} | java | public void stop() throws InterruptedException {
if (!isStarted.get()) {
throw new IllegalStateException("The StreamServer is not started");
}
stopServer();
stopClients();
closeSocket();
try {
waitForServerToTerminate();
isStarted.set(false);
stopServer();
} catch (InterruptedException e) {
logger.error("InterruptedException while waiting for termination", e);
throw e;
}
} | [
"public",
"void",
"stop",
"(",
")",
"throws",
"InterruptedException",
"{",
"if",
"(",
"!",
"isStarted",
".",
"get",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"The StreamServer is not started\"",
")",
";",
"}",
"stopServer",
"(",
")",
... | Stops the server thread.
@throws InterruptedException if a graceful shutdown didn't happen | [
"Stops",
"the",
"server",
"thread",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/StreamServer.java#L107-L122 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/StreamServer.java | StreamServer.closeQuietly | private void closeQuietly(Closeable c) {
if (c != null) {
try {
c.close();
} catch (Throwable t) {
logger.warn("Error closing, ignoring", t);
}
}
} | java | private void closeQuietly(Closeable c) {
if (c != null) {
try {
c.close();
} catch (Throwable t) {
logger.warn("Error closing, ignoring", t);
}
}
} | [
"private",
"void",
"closeQuietly",
"(",
"Closeable",
"c",
")",
"{",
"if",
"(",
"c",
"!=",
"null",
")",
"{",
"try",
"{",
"c",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Error closing, i... | Closes something quietly.
@param c closable | [
"Closes",
"something",
"quietly",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/StreamServer.java#L151-L159 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java | JsonRpcBasicServer.getHandlerInterfaces | protected Class<?>[] getHandlerInterfaces(final String serviceName) {
if (remoteInterface != null) {
return new Class<?>[]{remoteInterface};
} else if (Proxy.isProxyClass(handler.getClass())) {
return handler.getClass().getInterfaces();
} else {
return new Class<?>[]{handler.getClass()};
}
} | java | protected Class<?>[] getHandlerInterfaces(final String serviceName) {
if (remoteInterface != null) {
return new Class<?>[]{remoteInterface};
} else if (Proxy.isProxyClass(handler.getClass())) {
return handler.getClass().getInterfaces();
} else {
return new Class<?>[]{handler.getClass()};
}
} | [
"protected",
"Class",
"<",
"?",
">",
"[",
"]",
"getHandlerInterfaces",
"(",
"final",
"String",
"serviceName",
")",
"{",
"if",
"(",
"remoteInterface",
"!=",
"null",
")",
"{",
"return",
"new",
"Class",
"<",
"?",
">",
"[",
"]",
"{",
"remoteInterface",
"}",
... | Returns the handler's class or interfaces. The variable serviceName is ignored in this class.
@param serviceName the optional name of a service
@return the class | [
"Returns",
"the",
"handler",
"s",
"class",
"or",
"interfaces",
".",
"The",
"variable",
"serviceName",
"is",
"ignored",
"in",
"this",
"class",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java#L255-L263 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java | JsonRpcBasicServer.createResponseError | private ErrorObjectWithJsonError createResponseError(String jsonRpc, Object id, JsonError errorObject) {
ObjectNode response = mapper.createObjectNode();
ObjectNode error = mapper.createObjectNode();
error.put(ERROR_CODE, errorObject.code);
error.put(ERROR_MESSAGE, errorObject.message);
if (errorObject.data != null) {
error.set(DATA, mapper.valueToTree(errorObject.data));
}
response.put(JSONRPC, jsonRpc);
if (Integer.class.isInstance(id)) {
response.put(ID, Integer.class.cast(id).intValue());
} else if (Long.class.isInstance(id)) {
response.put(ID, Long.class.cast(id).longValue());
} else if (Float.class.isInstance(id)) {
response.put(ID, Float.class.cast(id).floatValue());
} else if (Double.class.isInstance(id)) {
response.put(ID, Double.class.cast(id).doubleValue());
} else if (BigDecimal.class.isInstance(id)) {
response.put(ID, BigDecimal.class.cast(id));
} else {
response.put(ID, String.class.cast(id));
}
response.set(ERROR, error);
return new ErrorObjectWithJsonError(response, errorObject);
} | java | private ErrorObjectWithJsonError createResponseError(String jsonRpc, Object id, JsonError errorObject) {
ObjectNode response = mapper.createObjectNode();
ObjectNode error = mapper.createObjectNode();
error.put(ERROR_CODE, errorObject.code);
error.put(ERROR_MESSAGE, errorObject.message);
if (errorObject.data != null) {
error.set(DATA, mapper.valueToTree(errorObject.data));
}
response.put(JSONRPC, jsonRpc);
if (Integer.class.isInstance(id)) {
response.put(ID, Integer.class.cast(id).intValue());
} else if (Long.class.isInstance(id)) {
response.put(ID, Long.class.cast(id).longValue());
} else if (Float.class.isInstance(id)) {
response.put(ID, Float.class.cast(id).floatValue());
} else if (Double.class.isInstance(id)) {
response.put(ID, Double.class.cast(id).doubleValue());
} else if (BigDecimal.class.isInstance(id)) {
response.put(ID, BigDecimal.class.cast(id));
} else {
response.put(ID, String.class.cast(id));
}
response.set(ERROR, error);
return new ErrorObjectWithJsonError(response, errorObject);
} | [
"private",
"ErrorObjectWithJsonError",
"createResponseError",
"(",
"String",
"jsonRpc",
",",
"Object",
"id",
",",
"JsonError",
"errorObject",
")",
"{",
"ObjectNode",
"response",
"=",
"mapper",
".",
"createObjectNode",
"(",
")",
";",
"ObjectNode",
"error",
"=",
"ma... | Convenience method for creating an error response.
@param jsonRpc the jsonrpc string
@param id the id
@param errorObject the error data (if any)
@return the error response | [
"Convenience",
"method",
"for",
"creating",
"an",
"error",
"response",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java#L555-L579 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java | JsonRpcBasicServer.createResponseSuccess | private ObjectNode createResponseSuccess(String jsonRpc, Object id, JsonNode result) {
ObjectNode response = mapper.createObjectNode();
response.put(JSONRPC, jsonRpc);
if (Integer.class.isInstance(id)) {
response.put(ID, Integer.class.cast(id).intValue());
} else if (Long.class.isInstance(id)) {
response.put(ID, Long.class.cast(id).longValue());
} else if (Float.class.isInstance(id)) {
response.put(ID, Float.class.cast(id).floatValue());
} else if (Double.class.isInstance(id)) {
response.put(ID, Double.class.cast(id).doubleValue());
} else if (BigDecimal.class.isInstance(id)) {
response.put(ID, BigDecimal.class.cast(id));
} else {
response.put(ID, String.class.cast(id));
}
response.set(RESULT, result);
return response;
} | java | private ObjectNode createResponseSuccess(String jsonRpc, Object id, JsonNode result) {
ObjectNode response = mapper.createObjectNode();
response.put(JSONRPC, jsonRpc);
if (Integer.class.isInstance(id)) {
response.put(ID, Integer.class.cast(id).intValue());
} else if (Long.class.isInstance(id)) {
response.put(ID, Long.class.cast(id).longValue());
} else if (Float.class.isInstance(id)) {
response.put(ID, Float.class.cast(id).floatValue());
} else if (Double.class.isInstance(id)) {
response.put(ID, Double.class.cast(id).doubleValue());
} else if (BigDecimal.class.isInstance(id)) {
response.put(ID, BigDecimal.class.cast(id));
} else {
response.put(ID, String.class.cast(id));
}
response.set(RESULT, result);
return response;
} | [
"private",
"ObjectNode",
"createResponseSuccess",
"(",
"String",
"jsonRpc",
",",
"Object",
"id",
",",
"JsonNode",
"result",
")",
"{",
"ObjectNode",
"response",
"=",
"mapper",
".",
"createObjectNode",
"(",
")",
";",
"response",
".",
"put",
"(",
"JSONRPC",
",",
... | Creates a success response.
@param jsonRpc the version string
@param id the id of the request
@param result the result object
@return the response object | [
"Creates",
"a",
"success",
"response",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcBasicServer.java#L589-L607 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/spring/rest/JsonRpcRestClient.java | JsonRpcRestClient.initRestTemplate | private void initRestTemplate() {
boolean isContainsConverter = false;
for (HttpMessageConverter<?> httpMessageConverter : this.restTemplate.getMessageConverters()) {
if (MappingJacksonRPC2HttpMessageConverter.class.isAssignableFrom(httpMessageConverter.getClass())) {
isContainsConverter = true;
break;
}
}
if (!isContainsConverter) {
final MappingJacksonRPC2HttpMessageConverter messageConverter = new MappingJacksonRPC2HttpMessageConverter();
messageConverter.setObjectMapper(this.getObjectMapper());
final List<HttpMessageConverter<?>> restMessageConverters = new ArrayList<>();
restMessageConverters.addAll(this.restTemplate.getMessageConverters());
// Place JSON-RPC converter on the first place!
restMessageConverters.add(0, messageConverter);
this.restTemplate.setMessageConverters(restMessageConverters);
}
// use specific JSON-RPC error handler if it has not been changed to custom
if (restTemplate.getErrorHandler() instanceof org.springframework.web.client.DefaultResponseErrorHandler) {
restTemplate.setErrorHandler(JsonRpcResponseErrorHandler.INSTANCE);
}
} | java | private void initRestTemplate() {
boolean isContainsConverter = false;
for (HttpMessageConverter<?> httpMessageConverter : this.restTemplate.getMessageConverters()) {
if (MappingJacksonRPC2HttpMessageConverter.class.isAssignableFrom(httpMessageConverter.getClass())) {
isContainsConverter = true;
break;
}
}
if (!isContainsConverter) {
final MappingJacksonRPC2HttpMessageConverter messageConverter = new MappingJacksonRPC2HttpMessageConverter();
messageConverter.setObjectMapper(this.getObjectMapper());
final List<HttpMessageConverter<?>> restMessageConverters = new ArrayList<>();
restMessageConverters.addAll(this.restTemplate.getMessageConverters());
// Place JSON-RPC converter on the first place!
restMessageConverters.add(0, messageConverter);
this.restTemplate.setMessageConverters(restMessageConverters);
}
// use specific JSON-RPC error handler if it has not been changed to custom
if (restTemplate.getErrorHandler() instanceof org.springframework.web.client.DefaultResponseErrorHandler) {
restTemplate.setErrorHandler(JsonRpcResponseErrorHandler.INSTANCE);
}
} | [
"private",
"void",
"initRestTemplate",
"(",
")",
"{",
"boolean",
"isContainsConverter",
"=",
"false",
";",
"for",
"(",
"HttpMessageConverter",
"<",
"?",
">",
"httpMessageConverter",
":",
"this",
".",
"restTemplate",
".",
"getMessageConverters",
"(",
")",
")",
"{... | Check RestTemplate contains required converters | [
"Check",
"RestTemplate",
"contains",
"required",
"converters"
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/spring/rest/JsonRpcRestClient.java#L67-L94 | train |
briandilley/jsonrpc4j | src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpClient.java | JsonRpcHttpClient.prepareConnection | private HttpURLConnection prepareConnection(Map<String, String> extraHeaders) throws IOException {
// create URLConnection
HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(connectionProxy);
connection.setConnectTimeout(connectionTimeoutMillis);
connection.setReadTimeout(readTimeoutMillis);
connection.setAllowUserInteraction(false);
connection.setDefaultUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestMethod("POST");
setupSsl(connection);
addHeaders(extraHeaders, connection);
return connection;
} | java | private HttpURLConnection prepareConnection(Map<String, String> extraHeaders) throws IOException {
// create URLConnection
HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(connectionProxy);
connection.setConnectTimeout(connectionTimeoutMillis);
connection.setReadTimeout(readTimeoutMillis);
connection.setAllowUserInteraction(false);
connection.setDefaultUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestMethod("POST");
setupSsl(connection);
addHeaders(extraHeaders, connection);
return connection;
} | [
"private",
"HttpURLConnection",
"prepareConnection",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"extraHeaders",
")",
"throws",
"IOException",
"{",
"// create URLConnection",
"HttpURLConnection",
"connection",
"=",
"(",
"HttpURLConnection",
")",
"serviceUrl",
".",
... | Prepares a connection to the server.
@param extraHeaders extra headers to add to the request
@return the unopened connection
@throws IOException | [
"Prepares",
"a",
"connection",
"to",
"the",
"server",
"."
] | d749762c9295b92d893677a8c7be2a14dd43b3bb | https://github.com/briandilley/jsonrpc4j/blob/d749762c9295b92d893677a8c7be2a14dd43b3bb/src/main/java/com/googlecode/jsonrpc4j/JsonRpcHttpClient.java#L195-L213 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.