id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
29,200 | jhunters/jprotobuf | jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/PreCompileMojo.java | PreCompileMojo.setSystemProperties | private void setSystemProperties()
{
if ( systemProperties != null )
{
originalSystemProperties = System.getProperties();
for ( Property systemProperty : systemProperties )
{
String value = systemProperty.getValue();
System.setProperty( systemProperty.getKey(), value == null ? "" : value );
}
}
} | java | private void setSystemProperties()
{
if ( systemProperties != null )
{
originalSystemProperties = System.getProperties();
for ( Property systemProperty : systemProperties )
{
String value = systemProperty.getValue();
System.setProperty( systemProperty.getKey(), value == null ? "" : value );
}
}
} | [
"private",
"void",
"setSystemProperties",
"(",
")",
"{",
"if",
"(",
"systemProperties",
"!=",
"null",
")",
"{",
"originalSystemProperties",
"=",
"System",
".",
"getProperties",
"(",
")",
";",
"for",
"(",
"Property",
"systemProperty",
":",
"systemProperties",
")",
"{",
"String",
"value",
"=",
"systemProperty",
".",
"getValue",
"(",
")",
";",
"System",
".",
"setProperty",
"(",
"systemProperty",
".",
"getKey",
"(",
")",
",",
"value",
"==",
"null",
"?",
"\"\"",
":",
"value",
")",
";",
"}",
"}",
"}"
] | Pass any given system properties to the java system properties. | [
"Pass",
"any",
"given",
"system",
"properties",
"to",
"the",
"java",
"system",
"properties",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/PreCompileMojo.java#L528-L539 |
29,201 | jhunters/jprotobuf | jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/PreCompileMojo.java | PreCompileMojo.getExecutablePomArtifact | private Artifact getExecutablePomArtifact( Artifact executableArtifact )
{
return this.artifactFactory.createBuildArtifact( executableArtifact.getGroupId(),
executableArtifact.getArtifactId(),
executableArtifact.getVersion(), "pom" );
} | java | private Artifact getExecutablePomArtifact( Artifact executableArtifact )
{
return this.artifactFactory.createBuildArtifact( executableArtifact.getGroupId(),
executableArtifact.getArtifactId(),
executableArtifact.getVersion(), "pom" );
} | [
"private",
"Artifact",
"getExecutablePomArtifact",
"(",
"Artifact",
"executableArtifact",
")",
"{",
"return",
"this",
".",
"artifactFactory",
".",
"createBuildArtifact",
"(",
"executableArtifact",
".",
"getGroupId",
"(",
")",
",",
"executableArtifact",
".",
"getArtifactId",
"(",
")",
",",
"executableArtifact",
".",
"getVersion",
"(",
")",
",",
"\"pom\"",
")",
";",
"}"
] | Get the artifact which refers to the POM of the executable artifact.
@param executableArtifact this artifact refers to the actual assembly.
@return an artifact which refers to the POM of the executable artifact. | [
"Get",
"the",
"artifact",
"which",
"refers",
"to",
"the",
"POM",
"of",
"the",
"executable",
"artifact",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/PreCompileMojo.java#L719-L724 |
29,202 | jhunters/jprotobuf | jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/PreCompileMojo.java | PreCompileMojo.waitFor | private void waitFor( long millis )
{
Object lock = new Object();
synchronized ( lock )
{
try
{
lock.wait( millis );
}
catch ( InterruptedException e )
{
Thread.currentThread().interrupt(); // good practice if don't throw
getLog().warn( "Spuriously interrupted while waiting for " + millis + "ms", e );
}
}
} | java | private void waitFor( long millis )
{
Object lock = new Object();
synchronized ( lock )
{
try
{
lock.wait( millis );
}
catch ( InterruptedException e )
{
Thread.currentThread().interrupt(); // good practice if don't throw
getLog().warn( "Spuriously interrupted while waiting for " + millis + "ms", e );
}
}
} | [
"private",
"void",
"waitFor",
"(",
"long",
"millis",
")",
"{",
"Object",
"lock",
"=",
"new",
"Object",
"(",
")",
";",
"synchronized",
"(",
"lock",
")",
"{",
"try",
"{",
"lock",
".",
"wait",
"(",
"millis",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"Thread",
".",
"currentThread",
"(",
")",
".",
"interrupt",
"(",
")",
";",
"// good practice if don't throw",
"getLog",
"(",
")",
".",
"warn",
"(",
"\"Spuriously interrupted while waiting for \"",
"+",
"millis",
"+",
"\"ms\"",
",",
"e",
")",
";",
"}",
"}",
"}"
] | Stop program execution for nn millis.
@param millis the number of millis-seconds to wait for, <code>0</code> stops program forever. | [
"Stop",
"program",
"execution",
"for",
"nn",
"millis",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/jprotobuf-precompile-plugin/src/main/java/com/baidu/jprotobuf/mojo/PreCompileMojo.java#L806-L821 |
29,203 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java | ProtobufIDLProxy.createMessageClass | private static List<Class<?>> createMessageClass(ProtoFile protoFile, boolean multi, boolean debug,
boolean generateSouceOnly, File sourceOutputDir, List<CodeDependent> cds, Set<String> compiledClass,
Set<String> enumNames, Set<String> packages, Map<String, String> mappedUniName, boolean isUniName) {
List<Type> types = protoFile.getTypes();
if (types == null || types.isEmpty()) {
throw new RuntimeException("No message defined in '.proto' IDL");
}
int count = 0;
Iterator<Type> iter = types.iterator();
while (iter.hasNext()) {
Type next = iter.next();
if (next instanceof EnumType) {
continue;
}
count++;
}
if (!multi && count != 1) {
throw new RuntimeException("Only one message defined allowed in '.proto' IDL");
}
List<Class<?>> ret = new ArrayList<Class<?>>(types.size());
List<MessageType> messageTypes = new ArrayList<MessageType>();
for (Type type : types) {
Class checkClass = checkClass(protoFile, type, mappedUniName, isUniName);
if (checkClass != null) {
ret.add(checkClass);
continue;
}
CodeDependent cd;
if (type instanceof MessageType) {
messageTypes.add((MessageType) type);
continue;
}
}
for (MessageType mt : messageTypes) {
CodeDependent cd;
cd = createCodeByType(protoFile, (MessageType) mt, enumNames, true, new ArrayList<Type>(), cds, packages,
mappedUniName, isUniName);
if (cd.isDepndency()) {
cds.add(cd);
} else {
cds.add(0, cd);
}
}
CodeDependent codeDependent;
// copy cds
List<CodeDependent> copiedCds = new ArrayList<ProtobufIDLProxy.CodeDependent>(cds);
while ((codeDependent = hasDependency(copiedCds, compiledClass)) != null) {
if (debug) {
CodePrinter.printCode(codeDependent.code, "generate jprotobuf code");
}
if (!generateSouceOnly) {
Class<?> newClass = JDKCompilerHelper.getJdkCompiler().compile(codeDependent.getClassName(),
codeDependent.code, ProtobufIDLProxy.class.getClassLoader(), null, -1);
ret.add(newClass);
} else {
// need to output source code to target path
writeSourceCode(codeDependent, sourceOutputDir);
}
}
return ret;
} | java | private static List<Class<?>> createMessageClass(ProtoFile protoFile, boolean multi, boolean debug,
boolean generateSouceOnly, File sourceOutputDir, List<CodeDependent> cds, Set<String> compiledClass,
Set<String> enumNames, Set<String> packages, Map<String, String> mappedUniName, boolean isUniName) {
List<Type> types = protoFile.getTypes();
if (types == null || types.isEmpty()) {
throw new RuntimeException("No message defined in '.proto' IDL");
}
int count = 0;
Iterator<Type> iter = types.iterator();
while (iter.hasNext()) {
Type next = iter.next();
if (next instanceof EnumType) {
continue;
}
count++;
}
if (!multi && count != 1) {
throw new RuntimeException("Only one message defined allowed in '.proto' IDL");
}
List<Class<?>> ret = new ArrayList<Class<?>>(types.size());
List<MessageType> messageTypes = new ArrayList<MessageType>();
for (Type type : types) {
Class checkClass = checkClass(protoFile, type, mappedUniName, isUniName);
if (checkClass != null) {
ret.add(checkClass);
continue;
}
CodeDependent cd;
if (type instanceof MessageType) {
messageTypes.add((MessageType) type);
continue;
}
}
for (MessageType mt : messageTypes) {
CodeDependent cd;
cd = createCodeByType(protoFile, (MessageType) mt, enumNames, true, new ArrayList<Type>(), cds, packages,
mappedUniName, isUniName);
if (cd.isDepndency()) {
cds.add(cd);
} else {
cds.add(0, cd);
}
}
CodeDependent codeDependent;
// copy cds
List<CodeDependent> copiedCds = new ArrayList<ProtobufIDLProxy.CodeDependent>(cds);
while ((codeDependent = hasDependency(copiedCds, compiledClass)) != null) {
if (debug) {
CodePrinter.printCode(codeDependent.code, "generate jprotobuf code");
}
if (!generateSouceOnly) {
Class<?> newClass = JDKCompilerHelper.getJdkCompiler().compile(codeDependent.getClassName(),
codeDependent.code, ProtobufIDLProxy.class.getClassLoader(), null, -1);
ret.add(newClass);
} else {
// need to output source code to target path
writeSourceCode(codeDependent, sourceOutputDir);
}
}
return ret;
} | [
"private",
"static",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"createMessageClass",
"(",
"ProtoFile",
"protoFile",
",",
"boolean",
"multi",
",",
"boolean",
"debug",
",",
"boolean",
"generateSouceOnly",
",",
"File",
"sourceOutputDir",
",",
"List",
"<",
"CodeDependent",
">",
"cds",
",",
"Set",
"<",
"String",
">",
"compiledClass",
",",
"Set",
"<",
"String",
">",
"enumNames",
",",
"Set",
"<",
"String",
">",
"packages",
",",
"Map",
"<",
"String",
",",
"String",
">",
"mappedUniName",
",",
"boolean",
"isUniName",
")",
"{",
"List",
"<",
"Type",
">",
"types",
"=",
"protoFile",
".",
"getTypes",
"(",
")",
";",
"if",
"(",
"types",
"==",
"null",
"||",
"types",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"No message defined in '.proto' IDL\"",
")",
";",
"}",
"int",
"count",
"=",
"0",
";",
"Iterator",
"<",
"Type",
">",
"iter",
"=",
"types",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"Type",
"next",
"=",
"iter",
".",
"next",
"(",
")",
";",
"if",
"(",
"next",
"instanceof",
"EnumType",
")",
"{",
"continue",
";",
"}",
"count",
"++",
";",
"}",
"if",
"(",
"!",
"multi",
"&&",
"count",
"!=",
"1",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Only one message defined allowed in '.proto' IDL\"",
")",
";",
"}",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"ret",
"=",
"new",
"ArrayList",
"<",
"Class",
"<",
"?",
">",
">",
"(",
"types",
".",
"size",
"(",
")",
")",
";",
"List",
"<",
"MessageType",
">",
"messageTypes",
"=",
"new",
"ArrayList",
"<",
"MessageType",
">",
"(",
")",
";",
"for",
"(",
"Type",
"type",
":",
"types",
")",
"{",
"Class",
"checkClass",
"=",
"checkClass",
"(",
"protoFile",
",",
"type",
",",
"mappedUniName",
",",
"isUniName",
")",
";",
"if",
"(",
"checkClass",
"!=",
"null",
")",
"{",
"ret",
".",
"add",
"(",
"checkClass",
")",
";",
"continue",
";",
"}",
"CodeDependent",
"cd",
";",
"if",
"(",
"type",
"instanceof",
"MessageType",
")",
"{",
"messageTypes",
".",
"add",
"(",
"(",
"MessageType",
")",
"type",
")",
";",
"continue",
";",
"}",
"}",
"for",
"(",
"MessageType",
"mt",
":",
"messageTypes",
")",
"{",
"CodeDependent",
"cd",
";",
"cd",
"=",
"createCodeByType",
"(",
"protoFile",
",",
"(",
"MessageType",
")",
"mt",
",",
"enumNames",
",",
"true",
",",
"new",
"ArrayList",
"<",
"Type",
">",
"(",
")",
",",
"cds",
",",
"packages",
",",
"mappedUniName",
",",
"isUniName",
")",
";",
"if",
"(",
"cd",
".",
"isDepndency",
"(",
")",
")",
"{",
"cds",
".",
"add",
"(",
"cd",
")",
";",
"}",
"else",
"{",
"cds",
".",
"add",
"(",
"0",
",",
"cd",
")",
";",
"}",
"}",
"CodeDependent",
"codeDependent",
";",
"// copy cds",
"List",
"<",
"CodeDependent",
">",
"copiedCds",
"=",
"new",
"ArrayList",
"<",
"ProtobufIDLProxy",
".",
"CodeDependent",
">",
"(",
"cds",
")",
";",
"while",
"(",
"(",
"codeDependent",
"=",
"hasDependency",
"(",
"copiedCds",
",",
"compiledClass",
")",
")",
"!=",
"null",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"CodePrinter",
".",
"printCode",
"(",
"codeDependent",
".",
"code",
",",
"\"generate jprotobuf code\"",
")",
";",
"}",
"if",
"(",
"!",
"generateSouceOnly",
")",
"{",
"Class",
"<",
"?",
">",
"newClass",
"=",
"JDKCompilerHelper",
".",
"getJdkCompiler",
"(",
")",
".",
"compile",
"(",
"codeDependent",
".",
"getClassName",
"(",
")",
",",
"codeDependent",
".",
"code",
",",
"ProtobufIDLProxy",
".",
"class",
".",
"getClassLoader",
"(",
")",
",",
"null",
",",
"-",
"1",
")",
";",
"ret",
".",
"add",
"(",
"newClass",
")",
";",
"}",
"else",
"{",
"// need to output source code to target path",
"writeSourceCode",
"(",
"codeDependent",
",",
"sourceOutputDir",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] | Creates the message class.
@param protoFile the proto file
@param multi the multi
@param debug the debug
@param generateSouceOnly the generate souce only
@param sourceOutputDir the source output dir
@param cds the cds
@param compiledClass the compiled class
@param enumNames the enum names
@param packages the packages
@param mappedUniName the mapped uni name
@param isUniName the is uni name
@return the list | [
"Creates",
"the",
"message",
"class",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java#L886-L955 |
29,204 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java | ProtobufIDLProxy.doCreate | private static Map<String, IDLProxyObject> doCreate(ProtoFile protoFile, boolean multi, boolean debug, File path,
boolean generateSouceOnly, File sourceOutputDir, List<CodeDependent> cds, Map<String, String> uniMappedName,
boolean isUniName) throws IOException {
return doCreatePro(Arrays.asList(protoFile), multi, debug, path, generateSouceOnly, sourceOutputDir, cds,
new HashSet<String>(), uniMappedName, isUniName);
} | java | private static Map<String, IDLProxyObject> doCreate(ProtoFile protoFile, boolean multi, boolean debug, File path,
boolean generateSouceOnly, File sourceOutputDir, List<CodeDependent> cds, Map<String, String> uniMappedName,
boolean isUniName) throws IOException {
return doCreatePro(Arrays.asList(protoFile), multi, debug, path, generateSouceOnly, sourceOutputDir, cds,
new HashSet<String>(), uniMappedName, isUniName);
} | [
"private",
"static",
"Map",
"<",
"String",
",",
"IDLProxyObject",
">",
"doCreate",
"(",
"ProtoFile",
"protoFile",
",",
"boolean",
"multi",
",",
"boolean",
"debug",
",",
"File",
"path",
",",
"boolean",
"generateSouceOnly",
",",
"File",
"sourceOutputDir",
",",
"List",
"<",
"CodeDependent",
">",
"cds",
",",
"Map",
"<",
"String",
",",
"String",
">",
"uniMappedName",
",",
"boolean",
"isUniName",
")",
"throws",
"IOException",
"{",
"return",
"doCreatePro",
"(",
"Arrays",
".",
"asList",
"(",
"protoFile",
")",
",",
"multi",
",",
"debug",
",",
"path",
",",
"generateSouceOnly",
",",
"sourceOutputDir",
",",
"cds",
",",
"new",
"HashSet",
"<",
"String",
">",
"(",
")",
",",
"uniMappedName",
",",
"isUniName",
")",
";",
"}"
] | Do create.
@param protoFile the proto file
@param multi the multi
@param debug the debug
@param path the path
@param generateSouceOnly the generate souce only
@param sourceOutputDir the source output dir
@param cds the cds
@param uniMappedName the uni mapped name
@param isUniName the is uni name
@return the map
@throws IOException Signals that an I/O exception has occurred. | [
"Do",
"create",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java#L1161-L1166 |
29,205 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java | ProtobufIDLProxy.getPackages | private static Set<String> getPackages(List<CodeDependent> cds) {
Set<String> ret = new HashSet<String>();
if (cds == null) {
return ret;
}
for (CodeDependent cd : cds) {
ret.add(cd.pkg);
}
return ret;
} | java | private static Set<String> getPackages(List<CodeDependent> cds) {
Set<String> ret = new HashSet<String>();
if (cds == null) {
return ret;
}
for (CodeDependent cd : cds) {
ret.add(cd.pkg);
}
return ret;
} | [
"private",
"static",
"Set",
"<",
"String",
">",
"getPackages",
"(",
"List",
"<",
"CodeDependent",
">",
"cds",
")",
"{",
"Set",
"<",
"String",
">",
"ret",
"=",
"new",
"HashSet",
"<",
"String",
">",
"(",
")",
";",
"if",
"(",
"cds",
"==",
"null",
")",
"{",
"return",
"ret",
";",
"}",
"for",
"(",
"CodeDependent",
"cd",
":",
"cds",
")",
"{",
"ret",
".",
"add",
"(",
"cd",
".",
"pkg",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Gets the packages.
@param cds the cds
@return the packages | [
"Gets",
"the",
"packages",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java#L1470-L1480 |
29,206 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/utils/compiler/ClassUtils.java | ClassUtils.newInstance | public static Object newInstance(String name) {
try {
return forName(name).newInstance();
} catch (InstantiationException e) {
throw new IllegalStateException(e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e.getMessage(), e);
}
} | java | public static Object newInstance(String name) {
try {
return forName(name).newInstance();
} catch (InstantiationException e) {
throw new IllegalStateException(e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e.getMessage(), e);
}
} | [
"public",
"static",
"Object",
"newInstance",
"(",
"String",
"name",
")",
"{",
"try",
"{",
"return",
"forName",
"(",
"name",
")",
".",
"newInstance",
"(",
")",
";",
"}",
"catch",
"(",
"InstantiationException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"}"
] | To new instance by class name
@param name
class name
@return new create instance | [
"To",
"new",
"instance",
"by",
"class",
"name"
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/compiler/ClassUtils.java#L56-L64 |
29,207 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/utils/compiler/ClassUtils.java | ClassUtils.doFormName | public static Class<?> doFormName(String className) throws ClassNotFoundException {
if ("boolean".equals(className))
return boolean.class;
if ("byte".equals(className))
return byte.class;
if ("char".equals(className))
return char.class;
if ("short".equals(className))
return short.class;
if ("int".equals(className))
return int.class;
if ("long".equals(className))
return long.class;
if ("float".equals(className))
return float.class;
if ("double".equals(className))
return double.class;
if ("boolean[]".equals(className))
return boolean[].class;
if ("byte[]".equals(className))
return byte[].class;
if ("char[]".equals(className))
return char[].class;
if ("short[]".equals(className))
return short[].class;
if ("int[]".equals(className))
return int[].class;
if ("long[]".equals(className))
return long[].class;
if ("float[]".equals(className))
return float[].class;
if ("double[]".equals(className))
return double[].class;
try {
return arrayForName(className);
} catch (ClassNotFoundException e) {
if (className.indexOf('.') == -1) { // 尝试java.lang包
try {
return arrayForName("java.lang." + className);
} catch (ClassNotFoundException e2) {
// 忽略尝试异常, 抛出原始异常
}
}
throw e;
}
} | java | public static Class<?> doFormName(String className) throws ClassNotFoundException {
if ("boolean".equals(className))
return boolean.class;
if ("byte".equals(className))
return byte.class;
if ("char".equals(className))
return char.class;
if ("short".equals(className))
return short.class;
if ("int".equals(className))
return int.class;
if ("long".equals(className))
return long.class;
if ("float".equals(className))
return float.class;
if ("double".equals(className))
return double.class;
if ("boolean[]".equals(className))
return boolean[].class;
if ("byte[]".equals(className))
return byte[].class;
if ("char[]".equals(className))
return char[].class;
if ("short[]".equals(className))
return short[].class;
if ("int[]".equals(className))
return int[].class;
if ("long[]".equals(className))
return long[].class;
if ("float[]".equals(className))
return float[].class;
if ("double[]".equals(className))
return double[].class;
try {
return arrayForName(className);
} catch (ClassNotFoundException e) {
if (className.indexOf('.') == -1) { // 尝试java.lang包
try {
return arrayForName("java.lang." + className);
} catch (ClassNotFoundException e2) {
// 忽略尝试异常, 抛出原始异常
}
}
throw e;
}
} | [
"public",
"static",
"Class",
"<",
"?",
">",
"doFormName",
"(",
"String",
"className",
")",
"throws",
"ClassNotFoundException",
"{",
"if",
"(",
"\"boolean\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"boolean",
".",
"class",
";",
"if",
"(",
"\"byte\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"byte",
".",
"class",
";",
"if",
"(",
"\"char\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"char",
".",
"class",
";",
"if",
"(",
"\"short\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"short",
".",
"class",
";",
"if",
"(",
"\"int\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"int",
".",
"class",
";",
"if",
"(",
"\"long\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"long",
".",
"class",
";",
"if",
"(",
"\"float\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"float",
".",
"class",
";",
"if",
"(",
"\"double\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"double",
".",
"class",
";",
"if",
"(",
"\"boolean[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"boolean",
"[",
"]",
".",
"class",
";",
"if",
"(",
"\"byte[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"byte",
"[",
"]",
".",
"class",
";",
"if",
"(",
"\"char[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"char",
"[",
"]",
".",
"class",
";",
"if",
"(",
"\"short[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"short",
"[",
"]",
".",
"class",
";",
"if",
"(",
"\"int[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"int",
"[",
"]",
".",
"class",
";",
"if",
"(",
"\"long[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"long",
"[",
"]",
".",
"class",
";",
"if",
"(",
"\"float[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"float",
"[",
"]",
".",
"class",
";",
"if",
"(",
"\"double[]\"",
".",
"equals",
"(",
"className",
")",
")",
"return",
"double",
"[",
"]",
".",
"class",
";",
"try",
"{",
"return",
"arrayForName",
"(",
"className",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"if",
"(",
"className",
".",
"indexOf",
"(",
"'",
"'",
")",
"==",
"-",
"1",
")",
"{",
"// 尝试java.lang包",
"try",
"{",
"return",
"arrayForName",
"(",
"\"java.lang.\"",
"+",
"className",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e2",
")",
"{",
"// 忽略尝试异常, 抛出原始异常",
"}",
"}",
"throw",
"e",
";",
"}",
"}"
] | Use Class.forname to initialize class.
@param className
class name
@return loaded class
@throws ClassNotFoundException
if class not found | [
"Use",
"Class",
".",
"forname",
"to",
"initialize",
"class",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/compiler/ClassUtils.java#L115-L160 |
29,208 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/utils/compiler/ClassUtils.java | ClassUtils.getBoxedClass | public static Class<?> getBoxedClass(Class<?> type) {
if (type == boolean.class) {
return Boolean.class;
} else if (type == char.class) {
return Character.class;
} else if (type == byte.class) {
return Byte.class;
} else if (type == short.class) {
return Short.class;
} else if (type == int.class) {
return Integer.class;
} else if (type == long.class) {
return Long.class;
} else if (type == float.class) {
return Float.class;
} else if (type == double.class) {
return Double.class;
} else {
return type;
}
} | java | public static Class<?> getBoxedClass(Class<?> type) {
if (type == boolean.class) {
return Boolean.class;
} else if (type == char.class) {
return Character.class;
} else if (type == byte.class) {
return Byte.class;
} else if (type == short.class) {
return Short.class;
} else if (type == int.class) {
return Integer.class;
} else if (type == long.class) {
return Long.class;
} else if (type == float.class) {
return Float.class;
} else if (type == double.class) {
return Double.class;
} else {
return type;
}
} | [
"public",
"static",
"Class",
"<",
"?",
">",
"getBoxedClass",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"if",
"(",
"type",
"==",
"boolean",
".",
"class",
")",
"{",
"return",
"Boolean",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"char",
".",
"class",
")",
"{",
"return",
"Character",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"byte",
".",
"class",
")",
"{",
"return",
"Byte",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"short",
".",
"class",
")",
"{",
"return",
"Short",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"int",
".",
"class",
")",
"{",
"return",
"Integer",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"long",
".",
"class",
")",
"{",
"return",
"Long",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"float",
".",
"class",
")",
"{",
"return",
"Float",
".",
"class",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"double",
".",
"class",
")",
"{",
"return",
"Double",
".",
"class",
";",
"}",
"else",
"{",
"return",
"type",
";",
"}",
"}"
] | Get boxed class for primitive type
@param type
primitive class type
@return Object class type | [
"Get",
"boxed",
"class",
"for",
"primitive",
"type"
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/compiler/ClassUtils.java#L180-L200 |
29,209 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/utils/ClassHelper.java | ClassHelper.hasDefaultConstructor | public static boolean hasDefaultConstructor(Class<?> cls) {
if (cls == null) {
return false;
}
try {
cls.getConstructor(new Class<?>[0]);
} catch (NoSuchMethodException e2) {
return false;
} catch (SecurityException e2) {
throw new IllegalArgumentException(e2.getMessage(), e2);
}
return true;
} | java | public static boolean hasDefaultConstructor(Class<?> cls) {
if (cls == null) {
return false;
}
try {
cls.getConstructor(new Class<?>[0]);
} catch (NoSuchMethodException e2) {
return false;
} catch (SecurityException e2) {
throw new IllegalArgumentException(e2.getMessage(), e2);
}
return true;
} | [
"public",
"static",
"boolean",
"hasDefaultConstructor",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"{",
"if",
"(",
"cls",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"cls",
".",
"getConstructor",
"(",
"new",
"Class",
"<",
"?",
">",
"[",
"0",
"]",
")",
";",
"}",
"catch",
"(",
"NoSuchMethodException",
"e2",
")",
"{",
"return",
"false",
";",
"}",
"catch",
"(",
"SecurityException",
"e2",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"e2",
".",
"getMessage",
"(",
")",
",",
"e2",
")",
";",
"}",
"return",
"true",
";",
"}"
] | To test class if has default constructor method
@param cls target class
@return true if has default constructor method | [
"To",
"test",
"class",
"if",
"has",
"default",
"constructor",
"method"
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ClassHelper.java#L310-L322 |
29,210 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/AbstractCodeGenerator.java | AbstractCodeGenerator.getMismatchTypeErroMessage | private String getMismatchTypeErroMessage(FieldType type, Field field) {
return "Type mismatch. @Protobuf required type '" + type.getJavaType() + "' but field type is '"
+ field.getType().getSimpleName() + "' of field name '" + field.getName() + "' on class "
+ field.getDeclaringClass().getCanonicalName();
} | java | private String getMismatchTypeErroMessage(FieldType type, Field field) {
return "Type mismatch. @Protobuf required type '" + type.getJavaType() + "' but field type is '"
+ field.getType().getSimpleName() + "' of field name '" + field.getName() + "' on class "
+ field.getDeclaringClass().getCanonicalName();
} | [
"private",
"String",
"getMismatchTypeErroMessage",
"(",
"FieldType",
"type",
",",
"Field",
"field",
")",
"{",
"return",
"\"Type mismatch. @Protobuf required type '\"",
"+",
"type",
".",
"getJavaType",
"(",
")",
"+",
"\"' but field type is '\"",
"+",
"field",
".",
"getType",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\"' of field name '\"",
"+",
"field",
".",
"getName",
"(",
")",
"+",
"\"' on class \"",
"+",
"field",
".",
"getDeclaringClass",
"(",
")",
".",
"getCanonicalName",
"(",
")",
";",
"}"
] | get error message info by type not matched.
@param type the type
@param field the field
@return error message for mismatch type | [
"get",
"error",
"message",
"info",
"by",
"type",
"not",
"matched",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/AbstractCodeGenerator.java#L177-L181 |
29,211 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ProtobufProxyUtils.java | ProtobufProxyUtils.fetchFieldInfos | public static List<FieldInfo> fetchFieldInfos(Class cls, boolean ignoreNoAnnotation) {
// if set ProtobufClass annotation
Annotation annotation = cls.getAnnotation(ProtobufClass.class);
Annotation zipZap = cls.getAnnotation(EnableZigZap.class);
boolean isZipZap = false;
if (zipZap != null) {
isZipZap = true;
}
boolean typeDefined = false;
List<Field> fields = null;
if (annotation == null) {
fields = FieldUtils.findMatchedFields(cls, Protobuf.class);
if (fields.isEmpty() && ignoreNoAnnotation) {
throw new IllegalArgumentException("Invalid class [" + cls.getName() + "] no field use annotation @"
+ Protobuf.class.getName() + " at class " + cls.getName());
}
} else {
typeDefined = true;
fields = FieldUtils.findMatchedFields(cls, null);
}
List<FieldInfo> fieldInfos = ProtobufProxyUtils.processDefaultValue(fields, typeDefined, isZipZap);
return fieldInfos;
} | java | public static List<FieldInfo> fetchFieldInfos(Class cls, boolean ignoreNoAnnotation) {
// if set ProtobufClass annotation
Annotation annotation = cls.getAnnotation(ProtobufClass.class);
Annotation zipZap = cls.getAnnotation(EnableZigZap.class);
boolean isZipZap = false;
if (zipZap != null) {
isZipZap = true;
}
boolean typeDefined = false;
List<Field> fields = null;
if (annotation == null) {
fields = FieldUtils.findMatchedFields(cls, Protobuf.class);
if (fields.isEmpty() && ignoreNoAnnotation) {
throw new IllegalArgumentException("Invalid class [" + cls.getName() + "] no field use annotation @"
+ Protobuf.class.getName() + " at class " + cls.getName());
}
} else {
typeDefined = true;
fields = FieldUtils.findMatchedFields(cls, null);
}
List<FieldInfo> fieldInfos = ProtobufProxyUtils.processDefaultValue(fields, typeDefined, isZipZap);
return fieldInfos;
} | [
"public",
"static",
"List",
"<",
"FieldInfo",
">",
"fetchFieldInfos",
"(",
"Class",
"cls",
",",
"boolean",
"ignoreNoAnnotation",
")",
"{",
"// if set ProtobufClass annotation\r",
"Annotation",
"annotation",
"=",
"cls",
".",
"getAnnotation",
"(",
"ProtobufClass",
".",
"class",
")",
";",
"Annotation",
"zipZap",
"=",
"cls",
".",
"getAnnotation",
"(",
"EnableZigZap",
".",
"class",
")",
";",
"boolean",
"isZipZap",
"=",
"false",
";",
"if",
"(",
"zipZap",
"!=",
"null",
")",
"{",
"isZipZap",
"=",
"true",
";",
"}",
"boolean",
"typeDefined",
"=",
"false",
";",
"List",
"<",
"Field",
">",
"fields",
"=",
"null",
";",
"if",
"(",
"annotation",
"==",
"null",
")",
"{",
"fields",
"=",
"FieldUtils",
".",
"findMatchedFields",
"(",
"cls",
",",
"Protobuf",
".",
"class",
")",
";",
"if",
"(",
"fields",
".",
"isEmpty",
"(",
")",
"&&",
"ignoreNoAnnotation",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid class [\"",
"+",
"cls",
".",
"getName",
"(",
")",
"+",
"\"] no field use annotation @\"",
"+",
"Protobuf",
".",
"class",
".",
"getName",
"(",
")",
"+",
"\" at class \"",
"+",
"cls",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"typeDefined",
"=",
"true",
";",
"fields",
"=",
"FieldUtils",
".",
"findMatchedFields",
"(",
"cls",
",",
"null",
")",
";",
"}",
"List",
"<",
"FieldInfo",
">",
"fieldInfos",
"=",
"ProtobufProxyUtils",
".",
"processDefaultValue",
"(",
"fields",
",",
"typeDefined",
",",
"isZipZap",
")",
";",
"return",
"fieldInfos",
";",
"}"
] | Fetch field infos.
@return the list | [
"Fetch",
"field",
"infos",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ProtobufProxyUtils.java#L90-L116 |
29,212 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ProtobufProxyUtils.java | ProtobufProxyUtils.isObjectType | public static boolean isObjectType(Class<?> cls) {
FieldType fieldType = TYPE_MAPPING.get(cls);
if (fieldType != null) {
return false;
}
return true;
} | java | public static boolean isObjectType(Class<?> cls) {
FieldType fieldType = TYPE_MAPPING.get(cls);
if (fieldType != null) {
return false;
}
return true;
} | [
"public",
"static",
"boolean",
"isObjectType",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"{",
"FieldType",
"fieldType",
"=",
"TYPE_MAPPING",
".",
"get",
"(",
"cls",
")",
";",
"if",
"(",
"fieldType",
"!=",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks if is object type.
@param cls the cls
@return true, if is object type | [
"Checks",
"if",
"is",
"object",
"type",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ProtobufProxyUtils.java#L263-L270 |
29,213 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ProtobufProxyUtils.java | ProtobufProxyUtils.processProtobufType | public static String processProtobufType(Class<?> cls) {
FieldType fieldType = TYPE_MAPPING.get(cls);
if (fieldType != null) {
return fieldType.getType();
}
return cls.getSimpleName();
} | java | public static String processProtobufType(Class<?> cls) {
FieldType fieldType = TYPE_MAPPING.get(cls);
if (fieldType != null) {
return fieldType.getType();
}
return cls.getSimpleName();
} | [
"public",
"static",
"String",
"processProtobufType",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"{",
"FieldType",
"fieldType",
"=",
"TYPE_MAPPING",
".",
"get",
"(",
"cls",
")",
";",
"if",
"(",
"fieldType",
"!=",
"null",
")",
"{",
"return",
"fieldType",
".",
"getType",
"(",
")",
";",
"}",
"return",
"cls",
".",
"getSimpleName",
"(",
")",
";",
"}"
] | Process protobuf type.
@param cls the cls
@return the string | [
"Process",
"protobuf",
"type",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ProtobufProxyUtils.java#L278-L285 |
29,214 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.getFiledType | public static String getFiledType(FieldType type, boolean isList) {
if ((type == FieldType.STRING || type == FieldType.BYTES) && !isList) {
return "com.google.protobuf.ByteString";
}
// add null check
String defineType = type.getJavaType();
if (isList) {
defineType = "List";
}
return defineType;
} | java | public static String getFiledType(FieldType type, boolean isList) {
if ((type == FieldType.STRING || type == FieldType.BYTES) && !isList) {
return "com.google.protobuf.ByteString";
}
// add null check
String defineType = type.getJavaType();
if (isList) {
defineType = "List";
}
return defineType;
} | [
"public",
"static",
"String",
"getFiledType",
"(",
"FieldType",
"type",
",",
"boolean",
"isList",
")",
"{",
"if",
"(",
"(",
"type",
"==",
"FieldType",
".",
"STRING",
"||",
"type",
"==",
"FieldType",
".",
"BYTES",
")",
"&&",
"!",
"isList",
")",
"{",
"return",
"\"com.google.protobuf.ByteString\"",
";",
"}",
"// add null check\r",
"String",
"defineType",
"=",
"type",
".",
"getJavaType",
"(",
")",
";",
"if",
"(",
"isList",
")",
"{",
"defineType",
"=",
"\"List\"",
";",
"}",
"return",
"defineType",
";",
"}"
] | Gets the filed type.
@param type the type
@param isList the is list
@return the filed type | [
"Gets",
"the",
"filed",
"type",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L179-L192 |
29,215 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.getMappedTypeSize | public static String getMappedTypeSize(FieldInfo field, int order, FieldType type, boolean isList, boolean isMap,
boolean debug, File path) {
String fieldName = getFieldName(order);
String spath = "null";
if (path != null) {
spath = "new java.io.File(\"" + path.getAbsolutePath().replace('\\', '/') + "\")";
}
String typeString = type.getType().toUpperCase();
if (isList) {
return "CodedConstant.computeListSize(" + order + ", " + fieldName + ", FieldType." + typeString + ", "
+ Boolean.valueOf(debug) + ", " + spath + "," + Boolean.valueOf(field.isPacked()) + ")"
+ CodeGenerator.JAVA_LINE_BREAK;
} else if (isMap) {
String joinedSentence = getMapFieldGenericParameterString(field);
return "CodedConstant.computeMapSize(" + order + ", " + fieldName + ", " + joinedSentence + ")"
+ CodeGenerator.JAVA_LINE_BREAK;
}
if (type == FieldType.OBJECT) {
return "CodedConstant.computeSize(" + order + "," + fieldName + ", FieldType." + typeString + ","
+ Boolean.valueOf(debug) + "," + spath + ")" + CodeGenerator.JAVA_LINE_BREAK;
}
String t = type.getType();
if (type == FieldType.STRING || type == FieldType.BYTES) {
t = "bytes";
}
t = capitalize(t);
boolean enumSpecial = false;
if (type == FieldType.ENUM) {
if (EnumReadable.class.isAssignableFrom(field.getField().getType())) {
String clsName = ClassHelper.getInternalName(field.getField().getType().getCanonicalName());
fieldName = "((" + clsName + ") " + fieldName + ").value()";
enumSpecial = true;
}
}
if (!enumSpecial) {
fieldName = fieldName + type.getToPrimitiveType();
}
return "com.google.protobuf.CodedOutputStream.compute" + t + "Size(" + order + "," + fieldName + ")"
+ CodeGenerator.JAVA_LINE_BREAK;
} | java | public static String getMappedTypeSize(FieldInfo field, int order, FieldType type, boolean isList, boolean isMap,
boolean debug, File path) {
String fieldName = getFieldName(order);
String spath = "null";
if (path != null) {
spath = "new java.io.File(\"" + path.getAbsolutePath().replace('\\', '/') + "\")";
}
String typeString = type.getType().toUpperCase();
if (isList) {
return "CodedConstant.computeListSize(" + order + ", " + fieldName + ", FieldType." + typeString + ", "
+ Boolean.valueOf(debug) + ", " + spath + "," + Boolean.valueOf(field.isPacked()) + ")"
+ CodeGenerator.JAVA_LINE_BREAK;
} else if (isMap) {
String joinedSentence = getMapFieldGenericParameterString(field);
return "CodedConstant.computeMapSize(" + order + ", " + fieldName + ", " + joinedSentence + ")"
+ CodeGenerator.JAVA_LINE_BREAK;
}
if (type == FieldType.OBJECT) {
return "CodedConstant.computeSize(" + order + "," + fieldName + ", FieldType." + typeString + ","
+ Boolean.valueOf(debug) + "," + spath + ")" + CodeGenerator.JAVA_LINE_BREAK;
}
String t = type.getType();
if (type == FieldType.STRING || type == FieldType.BYTES) {
t = "bytes";
}
t = capitalize(t);
boolean enumSpecial = false;
if (type == FieldType.ENUM) {
if (EnumReadable.class.isAssignableFrom(field.getField().getType())) {
String clsName = ClassHelper.getInternalName(field.getField().getType().getCanonicalName());
fieldName = "((" + clsName + ") " + fieldName + ").value()";
enumSpecial = true;
}
}
if (!enumSpecial) {
fieldName = fieldName + type.getToPrimitiveType();
}
return "com.google.protobuf.CodedOutputStream.compute" + t + "Size(" + order + "," + fieldName + ")"
+ CodeGenerator.JAVA_LINE_BREAK;
} | [
"public",
"static",
"String",
"getMappedTypeSize",
"(",
"FieldInfo",
"field",
",",
"int",
"order",
",",
"FieldType",
"type",
",",
"boolean",
"isList",
",",
"boolean",
"isMap",
",",
"boolean",
"debug",
",",
"File",
"path",
")",
"{",
"String",
"fieldName",
"=",
"getFieldName",
"(",
"order",
")",
";",
"String",
"spath",
"=",
"\"null\"",
";",
"if",
"(",
"path",
"!=",
"null",
")",
"{",
"spath",
"=",
"\"new java.io.File(\\\"\"",
"+",
"path",
".",
"getAbsolutePath",
"(",
")",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
"+",
"\"\\\")\"",
";",
"}",
"String",
"typeString",
"=",
"type",
".",
"getType",
"(",
")",
".",
"toUpperCase",
"(",
")",
";",
"if",
"(",
"isList",
")",
"{",
"return",
"\"CodedConstant.computeListSize(\"",
"+",
"order",
"+",
"\", \"",
"+",
"fieldName",
"+",
"\", FieldType.\"",
"+",
"typeString",
"+",
"\", \"",
"+",
"Boolean",
".",
"valueOf",
"(",
"debug",
")",
"+",
"\", \"",
"+",
"spath",
"+",
"\",\"",
"+",
"Boolean",
".",
"valueOf",
"(",
"field",
".",
"isPacked",
"(",
")",
")",
"+",
"\")\"",
"+",
"CodeGenerator",
".",
"JAVA_LINE_BREAK",
";",
"}",
"else",
"if",
"(",
"isMap",
")",
"{",
"String",
"joinedSentence",
"=",
"getMapFieldGenericParameterString",
"(",
"field",
")",
";",
"return",
"\"CodedConstant.computeMapSize(\"",
"+",
"order",
"+",
"\", \"",
"+",
"fieldName",
"+",
"\", \"",
"+",
"joinedSentence",
"+",
"\")\"",
"+",
"CodeGenerator",
".",
"JAVA_LINE_BREAK",
";",
"}",
"if",
"(",
"type",
"==",
"FieldType",
".",
"OBJECT",
")",
"{",
"return",
"\"CodedConstant.computeSize(\"",
"+",
"order",
"+",
"\",\"",
"+",
"fieldName",
"+",
"\", FieldType.\"",
"+",
"typeString",
"+",
"\",\"",
"+",
"Boolean",
".",
"valueOf",
"(",
"debug",
")",
"+",
"\",\"",
"+",
"spath",
"+",
"\")\"",
"+",
"CodeGenerator",
".",
"JAVA_LINE_BREAK",
";",
"}",
"String",
"t",
"=",
"type",
".",
"getType",
"(",
")",
";",
"if",
"(",
"type",
"==",
"FieldType",
".",
"STRING",
"||",
"type",
"==",
"FieldType",
".",
"BYTES",
")",
"{",
"t",
"=",
"\"bytes\"",
";",
"}",
"t",
"=",
"capitalize",
"(",
"t",
")",
";",
"boolean",
"enumSpecial",
"=",
"false",
";",
"if",
"(",
"type",
"==",
"FieldType",
".",
"ENUM",
")",
"{",
"if",
"(",
"EnumReadable",
".",
"class",
".",
"isAssignableFrom",
"(",
"field",
".",
"getField",
"(",
")",
".",
"getType",
"(",
")",
")",
")",
"{",
"String",
"clsName",
"=",
"ClassHelper",
".",
"getInternalName",
"(",
"field",
".",
"getField",
"(",
")",
".",
"getType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
";",
"fieldName",
"=",
"\"((\"",
"+",
"clsName",
"+",
"\") \"",
"+",
"fieldName",
"+",
"\").value()\"",
";",
"enumSpecial",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"enumSpecial",
")",
"{",
"fieldName",
"=",
"fieldName",
"+",
"type",
".",
"getToPrimitiveType",
"(",
")",
";",
"}",
"return",
"\"com.google.protobuf.CodedOutputStream.compute\"",
"+",
"t",
"+",
"\"Size(\"",
"+",
"order",
"+",
"\",\"",
"+",
"fieldName",
"+",
"\")\"",
"+",
"CodeGenerator",
".",
"JAVA_LINE_BREAK",
";",
"}"
] | Gets the mapped type size.
@param field field
@param order field order
@param type field type
@param isList is field type is a {@link List}
@param isMap the is map
@param debug debug mode if true enable debug.
@param path the path
@return full java expression | [
"Gets",
"the",
"mapped",
"type",
"size",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L227-L273 |
29,216 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.getMapFieldGenericParameterString | public static String getMapFieldGenericParameterString(FieldInfo field) {
FieldType fieldType = ProtobufProxyUtils.TYPE_MAPPING.get(field.getGenericKeyType());
String keyClass;
String defaultKeyValue;
if (fieldType == null) {
// may be object or enum
if (Enum.class.isAssignableFrom(field.getGenericKeyType())) {
keyClass = WIREFORMAT_CLSNAME + ".ENUM";
Class<?> declaringClass = field.getGenericKeyType();
Field[] fields = declaringClass.getFields();
if (fields != null && fields.length > 0) {
defaultKeyValue = ClassHelper.getInternalName(field.getGenericKeyType().getCanonicalName()) + "."
+ fields[0].getName();
} else {
defaultKeyValue = "0";
}
} else {
keyClass = WIREFORMAT_CLSNAME + ".MESSAGE";
// check constructor
boolean hasDefaultConstructor = ClassHelper.hasDefaultConstructor(field.getGenericKeyType());
if (!hasDefaultConstructor) {
throw new IllegalArgumentException("Class '" + field.getGenericKeyType().getCanonicalName()
+ "' must has default constructor method with no parameters.");
}
defaultKeyValue = "new " + ClassHelper.getInternalName(field.getGenericKeyType().getCanonicalName()) + "()";
}
} else {
keyClass = WIREFORMAT_CLSNAME + "." + fieldType.toString();
defaultKeyValue = fieldType.getDefaultValue();
}
fieldType = ProtobufProxyUtils.TYPE_MAPPING.get(field.getGenericeValueType());
String valueClass;
String defaultValueValue;
if (fieldType == null) {
// may be object or enum
if (Enum.class.isAssignableFrom(field.getGenericeValueType())) {
valueClass = WIREFORMAT_CLSNAME + ".ENUM";
Class<?> declaringClass = field.getGenericeValueType();
Field[] fields = declaringClass.getFields();
if (fields != null && fields.length > 0) {
defaultValueValue = ClassHelper.getInternalName(field.getGenericeValueType().getCanonicalName()) + "."
+ fields[0].getName();
} else {
defaultValueValue = "0";
}
} else {
valueClass = WIREFORMAT_CLSNAME + ".MESSAGE";
// check constructor
boolean hasDefaultConstructor = ClassHelper.hasDefaultConstructor(field.getGenericeValueType());
if (!hasDefaultConstructor) {
throw new IllegalArgumentException("Class '" + field.getGenericeValueType().getCanonicalName()
+ "' must has default constructor method with no parameters.");
}
defaultValueValue = "new " + ClassHelper.getInternalName(field.getGenericeValueType().getCanonicalName()) + "()";
}
} else {
valueClass = WIREFORMAT_CLSNAME + "." + fieldType.toString();
defaultValueValue = fieldType.getDefaultValue();
}
String joinedSentence = keyClass + "," + defaultKeyValue + "," + valueClass + "," + defaultValueValue;
return joinedSentence;
} | java | public static String getMapFieldGenericParameterString(FieldInfo field) {
FieldType fieldType = ProtobufProxyUtils.TYPE_MAPPING.get(field.getGenericKeyType());
String keyClass;
String defaultKeyValue;
if (fieldType == null) {
// may be object or enum
if (Enum.class.isAssignableFrom(field.getGenericKeyType())) {
keyClass = WIREFORMAT_CLSNAME + ".ENUM";
Class<?> declaringClass = field.getGenericKeyType();
Field[] fields = declaringClass.getFields();
if (fields != null && fields.length > 0) {
defaultKeyValue = ClassHelper.getInternalName(field.getGenericKeyType().getCanonicalName()) + "."
+ fields[0].getName();
} else {
defaultKeyValue = "0";
}
} else {
keyClass = WIREFORMAT_CLSNAME + ".MESSAGE";
// check constructor
boolean hasDefaultConstructor = ClassHelper.hasDefaultConstructor(field.getGenericKeyType());
if (!hasDefaultConstructor) {
throw new IllegalArgumentException("Class '" + field.getGenericKeyType().getCanonicalName()
+ "' must has default constructor method with no parameters.");
}
defaultKeyValue = "new " + ClassHelper.getInternalName(field.getGenericKeyType().getCanonicalName()) + "()";
}
} else {
keyClass = WIREFORMAT_CLSNAME + "." + fieldType.toString();
defaultKeyValue = fieldType.getDefaultValue();
}
fieldType = ProtobufProxyUtils.TYPE_MAPPING.get(field.getGenericeValueType());
String valueClass;
String defaultValueValue;
if (fieldType == null) {
// may be object or enum
if (Enum.class.isAssignableFrom(field.getGenericeValueType())) {
valueClass = WIREFORMAT_CLSNAME + ".ENUM";
Class<?> declaringClass = field.getGenericeValueType();
Field[] fields = declaringClass.getFields();
if (fields != null && fields.length > 0) {
defaultValueValue = ClassHelper.getInternalName(field.getGenericeValueType().getCanonicalName()) + "."
+ fields[0].getName();
} else {
defaultValueValue = "0";
}
} else {
valueClass = WIREFORMAT_CLSNAME + ".MESSAGE";
// check constructor
boolean hasDefaultConstructor = ClassHelper.hasDefaultConstructor(field.getGenericeValueType());
if (!hasDefaultConstructor) {
throw new IllegalArgumentException("Class '" + field.getGenericeValueType().getCanonicalName()
+ "' must has default constructor method with no parameters.");
}
defaultValueValue = "new " + ClassHelper.getInternalName(field.getGenericeValueType().getCanonicalName()) + "()";
}
} else {
valueClass = WIREFORMAT_CLSNAME + "." + fieldType.toString();
defaultValueValue = fieldType.getDefaultValue();
}
String joinedSentence = keyClass + "," + defaultKeyValue + "," + valueClass + "," + defaultValueValue;
return joinedSentence;
} | [
"public",
"static",
"String",
"getMapFieldGenericParameterString",
"(",
"FieldInfo",
"field",
")",
"{",
"FieldType",
"fieldType",
"=",
"ProtobufProxyUtils",
".",
"TYPE_MAPPING",
".",
"get",
"(",
"field",
".",
"getGenericKeyType",
"(",
")",
")",
";",
"String",
"keyClass",
";",
"String",
"defaultKeyValue",
";",
"if",
"(",
"fieldType",
"==",
"null",
")",
"{",
"// may be object or enum\r",
"if",
"(",
"Enum",
".",
"class",
".",
"isAssignableFrom",
"(",
"field",
".",
"getGenericKeyType",
"(",
")",
")",
")",
"{",
"keyClass",
"=",
"WIREFORMAT_CLSNAME",
"+",
"\".ENUM\"",
";",
"Class",
"<",
"?",
">",
"declaringClass",
"=",
"field",
".",
"getGenericKeyType",
"(",
")",
";",
"Field",
"[",
"]",
"fields",
"=",
"declaringClass",
".",
"getFields",
"(",
")",
";",
"if",
"(",
"fields",
"!=",
"null",
"&&",
"fields",
".",
"length",
">",
"0",
")",
"{",
"defaultKeyValue",
"=",
"ClassHelper",
".",
"getInternalName",
"(",
"field",
".",
"getGenericKeyType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
"+",
"\".\"",
"+",
"fields",
"[",
"0",
"]",
".",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"defaultKeyValue",
"=",
"\"0\"",
";",
"}",
"}",
"else",
"{",
"keyClass",
"=",
"WIREFORMAT_CLSNAME",
"+",
"\".MESSAGE\"",
";",
"// check constructor\r",
"boolean",
"hasDefaultConstructor",
"=",
"ClassHelper",
".",
"hasDefaultConstructor",
"(",
"field",
".",
"getGenericKeyType",
"(",
")",
")",
";",
"if",
"(",
"!",
"hasDefaultConstructor",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Class '\"",
"+",
"field",
".",
"getGenericKeyType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
"+",
"\"' must has default constructor method with no parameters.\"",
")",
";",
"}",
"defaultKeyValue",
"=",
"\"new \"",
"+",
"ClassHelper",
".",
"getInternalName",
"(",
"field",
".",
"getGenericKeyType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
"+",
"\"()\"",
";",
"}",
"}",
"else",
"{",
"keyClass",
"=",
"WIREFORMAT_CLSNAME",
"+",
"\".\"",
"+",
"fieldType",
".",
"toString",
"(",
")",
";",
"defaultKeyValue",
"=",
"fieldType",
".",
"getDefaultValue",
"(",
")",
";",
"}",
"fieldType",
"=",
"ProtobufProxyUtils",
".",
"TYPE_MAPPING",
".",
"get",
"(",
"field",
".",
"getGenericeValueType",
"(",
")",
")",
";",
"String",
"valueClass",
";",
"String",
"defaultValueValue",
";",
"if",
"(",
"fieldType",
"==",
"null",
")",
"{",
"// may be object or enum\r",
"if",
"(",
"Enum",
".",
"class",
".",
"isAssignableFrom",
"(",
"field",
".",
"getGenericeValueType",
"(",
")",
")",
")",
"{",
"valueClass",
"=",
"WIREFORMAT_CLSNAME",
"+",
"\".ENUM\"",
";",
"Class",
"<",
"?",
">",
"declaringClass",
"=",
"field",
".",
"getGenericeValueType",
"(",
")",
";",
"Field",
"[",
"]",
"fields",
"=",
"declaringClass",
".",
"getFields",
"(",
")",
";",
"if",
"(",
"fields",
"!=",
"null",
"&&",
"fields",
".",
"length",
">",
"0",
")",
"{",
"defaultValueValue",
"=",
"ClassHelper",
".",
"getInternalName",
"(",
"field",
".",
"getGenericeValueType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
"+",
"\".\"",
"+",
"fields",
"[",
"0",
"]",
".",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"defaultValueValue",
"=",
"\"0\"",
";",
"}",
"}",
"else",
"{",
"valueClass",
"=",
"WIREFORMAT_CLSNAME",
"+",
"\".MESSAGE\"",
";",
"// check constructor\r",
"boolean",
"hasDefaultConstructor",
"=",
"ClassHelper",
".",
"hasDefaultConstructor",
"(",
"field",
".",
"getGenericeValueType",
"(",
")",
")",
";",
"if",
"(",
"!",
"hasDefaultConstructor",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Class '\"",
"+",
"field",
".",
"getGenericeValueType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
"+",
"\"' must has default constructor method with no parameters.\"",
")",
";",
"}",
"defaultValueValue",
"=",
"\"new \"",
"+",
"ClassHelper",
".",
"getInternalName",
"(",
"field",
".",
"getGenericeValueType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
"+",
"\"()\"",
";",
"}",
"}",
"else",
"{",
"valueClass",
"=",
"WIREFORMAT_CLSNAME",
"+",
"\".\"",
"+",
"fieldType",
".",
"toString",
"(",
")",
";",
"defaultValueValue",
"=",
"fieldType",
".",
"getDefaultValue",
"(",
")",
";",
"}",
"String",
"joinedSentence",
"=",
"keyClass",
"+",
"\",\"",
"+",
"defaultKeyValue",
"+",
"\",\"",
"+",
"valueClass",
"+",
"\",\"",
"+",
"defaultValueValue",
";",
"return",
"joinedSentence",
";",
"}"
] | Gets the map field generic parameter string.
@param field the field
@return the map field generic parameter string | [
"Gets",
"the",
"map",
"field",
"generic",
"parameter",
"string",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L281-L345 |
29,217 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.computeMapSize | public static <K, V> int computeMapSize(int order, Map<K, V> map, com.google.protobuf.WireFormat.FieldType keyType,
K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue) {
int size = 0;
for (java.util.Map.Entry<K, V> entry : map.entrySet()) {
com.baidu.bjf.remoting.protobuf.MapEntry<K, V> valuesDefaultEntry = com.baidu.bjf.remoting.protobuf.MapEntry
.<K, V> newDefaultInstance(null, keyType, defaultKey, valueType, defalutValue);
com.baidu.bjf.remoting.protobuf.MapEntry<K, V> values =
valuesDefaultEntry.newBuilderForType().setKey(entry.getKey()).setValue(entry.getValue()).build();
size += com.google.protobuf.CodedOutputStream.computeMessageSize(order, values);
}
return size;
} | java | public static <K, V> int computeMapSize(int order, Map<K, V> map, com.google.protobuf.WireFormat.FieldType keyType,
K defaultKey, com.google.protobuf.WireFormat.FieldType valueType, V defalutValue) {
int size = 0;
for (java.util.Map.Entry<K, V> entry : map.entrySet()) {
com.baidu.bjf.remoting.protobuf.MapEntry<K, V> valuesDefaultEntry = com.baidu.bjf.remoting.protobuf.MapEntry
.<K, V> newDefaultInstance(null, keyType, defaultKey, valueType, defalutValue);
com.baidu.bjf.remoting.protobuf.MapEntry<K, V> values =
valuesDefaultEntry.newBuilderForType().setKey(entry.getKey()).setValue(entry.getValue()).build();
size += com.google.protobuf.CodedOutputStream.computeMessageSize(order, values);
}
return size;
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"int",
"computeMapSize",
"(",
"int",
"order",
",",
"Map",
"<",
"K",
",",
"V",
">",
"map",
",",
"com",
".",
"google",
".",
"protobuf",
".",
"WireFormat",
".",
"FieldType",
"keyType",
",",
"K",
"defaultKey",
",",
"com",
".",
"google",
".",
"protobuf",
".",
"WireFormat",
".",
"FieldType",
"valueType",
",",
"V",
"defalutValue",
")",
"{",
"int",
"size",
"=",
"0",
";",
"for",
"(",
"java",
".",
"util",
".",
"Map",
".",
"Entry",
"<",
"K",
",",
"V",
">",
"entry",
":",
"map",
".",
"entrySet",
"(",
")",
")",
"{",
"com",
".",
"baidu",
".",
"bjf",
".",
"remoting",
".",
"protobuf",
".",
"MapEntry",
"<",
"K",
",",
"V",
">",
"valuesDefaultEntry",
"=",
"com",
".",
"baidu",
".",
"bjf",
".",
"remoting",
".",
"protobuf",
".",
"MapEntry",
".",
"<",
"K",
",",
"V",
">",
"newDefaultInstance",
"(",
"null",
",",
"keyType",
",",
"defaultKey",
",",
"valueType",
",",
"defalutValue",
")",
";",
"com",
".",
"baidu",
".",
"bjf",
".",
"remoting",
".",
"protobuf",
".",
"MapEntry",
"<",
"K",
",",
"V",
">",
"values",
"=",
"valuesDefaultEntry",
".",
"newBuilderForType",
"(",
")",
".",
"setKey",
"(",
"entry",
".",
"getKey",
"(",
")",
")",
".",
"setValue",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
".",
"build",
"(",
")",
";",
"size",
"+=",
"com",
".",
"google",
".",
"protobuf",
".",
"CodedOutputStream",
".",
"computeMessageSize",
"(",
"order",
",",
"values",
")",
";",
"}",
"return",
"size",
";",
"}"
] | Compute map size.
@param <K> the key type
@param <V> the value type
@param order the order
@param map the map
@param keyType the key type
@param defaultKey the default key
@param valueType the value type
@param defalutValue the defalut value
@return the int | [
"Compute",
"map",
"size",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L428-L441 |
29,218 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.putMapValue | public static <K, V> void putMapValue(CodedInputStream input, Map<K, V> map,
com.google.protobuf.WireFormat.FieldType keyType, K defaultKey,
com.google.protobuf.WireFormat.FieldType valueType, V defalutValue) throws IOException {
putMapValue(input, map, keyType, defaultKey, valueType, defalutValue, null);
} | java | public static <K, V> void putMapValue(CodedInputStream input, Map<K, V> map,
com.google.protobuf.WireFormat.FieldType keyType, K defaultKey,
com.google.protobuf.WireFormat.FieldType valueType, V defalutValue) throws IOException {
putMapValue(input, map, keyType, defaultKey, valueType, defalutValue, null);
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"void",
"putMapValue",
"(",
"CodedInputStream",
"input",
",",
"Map",
"<",
"K",
",",
"V",
">",
"map",
",",
"com",
".",
"google",
".",
"protobuf",
".",
"WireFormat",
".",
"FieldType",
"keyType",
",",
"K",
"defaultKey",
",",
"com",
".",
"google",
".",
"protobuf",
".",
"WireFormat",
".",
"FieldType",
"valueType",
",",
"V",
"defalutValue",
")",
"throws",
"IOException",
"{",
"putMapValue",
"(",
"input",
",",
"map",
",",
"keyType",
",",
"defaultKey",
",",
"valueType",
",",
"defalutValue",
",",
"null",
")",
";",
"}"
] | Put map value.
@param <K> the key type
@param <V> the value type
@param input the input
@param map the map
@param keyType the key type
@param defaultKey the default key
@param valueType the value type
@param defalutValue the defalut value
@throws IOException Signals that an I/O exception has occurred. | [
"Put",
"map",
"value",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L456-L461 |
29,219 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.computeObjectSizeNoTag | public static int computeObjectSizeNoTag(Object o) {
int size = 0;
if (o == null) {
return size;
}
Class cls = o.getClass();
Codec target = ProtobufProxy.create(cls);
try {
size = target.size(o);
size = size + CodedOutputStream.computeRawVarint32Size(size);
return size;
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
} | java | public static int computeObjectSizeNoTag(Object o) {
int size = 0;
if (o == null) {
return size;
}
Class cls = o.getClass();
Codec target = ProtobufProxy.create(cls);
try {
size = target.size(o);
size = size + CodedOutputStream.computeRawVarint32Size(size);
return size;
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
} | [
"public",
"static",
"int",
"computeObjectSizeNoTag",
"(",
"Object",
"o",
")",
"{",
"int",
"size",
"=",
"0",
";",
"if",
"(",
"o",
"==",
"null",
")",
"{",
"return",
"size",
";",
"}",
"Class",
"cls",
"=",
"o",
".",
"getClass",
"(",
")",
";",
"Codec",
"target",
"=",
"ProtobufProxy",
".",
"create",
"(",
"cls",
")",
";",
"try",
"{",
"size",
"=",
"target",
".",
"size",
"(",
"o",
")",
";",
"size",
"=",
"size",
"+",
"CodedOutputStream",
".",
"computeRawVarint32Size",
"(",
"size",
")",
";",
"return",
"size",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"}"
] | Compute object size no tag.
@param o the o
@return the int | [
"Compute",
"object",
"size",
"no",
"tag",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L530-L545 |
29,220 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.writeToList | public static void writeToList(CodedOutputStream out, int order, FieldType type, List list) throws IOException {
writeToList(out, order, type, list, false);
} | java | public static void writeToList(CodedOutputStream out, int order, FieldType type, List list) throws IOException {
writeToList(out, order, type, list, false);
} | [
"public",
"static",
"void",
"writeToList",
"(",
"CodedOutputStream",
"out",
",",
"int",
"order",
",",
"FieldType",
"type",
",",
"List",
"list",
")",
"throws",
"IOException",
"{",
"writeToList",
"(",
"out",
",",
"order",
",",
"type",
",",
"list",
",",
"false",
")",
";",
"}"
] | Write to list.
@param out the out
@param order the order
@param type the type
@param list the list
@throws IOException Signals that an I/O exception has occurred. | [
"Write",
"to",
"list",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L686-L688 |
29,221 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.writeObject | public static void writeObject(CodedOutputStream out, int order, FieldType type, Object o, boolean list)
throws IOException {
writeObject(out, order, type, o, list, true);
} | java | public static void writeObject(CodedOutputStream out, int order, FieldType type, Object o, boolean list)
throws IOException {
writeObject(out, order, type, o, list, true);
} | [
"public",
"static",
"void",
"writeObject",
"(",
"CodedOutputStream",
"out",
",",
"int",
"order",
",",
"FieldType",
"type",
",",
"Object",
"o",
",",
"boolean",
"list",
")",
"throws",
"IOException",
"{",
"writeObject",
"(",
"out",
",",
"order",
",",
"type",
",",
"o",
",",
"list",
",",
"true",
")",
";",
"}"
] | Write object.
@param out the out
@param order the order
@param type the type
@param o the o
@param list the list
@throws IOException Signals that an I/O exception has occurred. | [
"Write",
"object",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L731-L734 |
29,222 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.getEnumValue | public static int getEnumValue(Enum en) {
if (en != null) {
int toCompareValue;
if (en instanceof EnumReadable) {
toCompareValue = ((EnumReadable) en).value();
} else {
toCompareValue = en.ordinal();
}
return toCompareValue;
}
return -1;
} | java | public static int getEnumValue(Enum en) {
if (en != null) {
int toCompareValue;
if (en instanceof EnumReadable) {
toCompareValue = ((EnumReadable) en).value();
} else {
toCompareValue = en.ordinal();
}
return toCompareValue;
}
return -1;
} | [
"public",
"static",
"int",
"getEnumValue",
"(",
"Enum",
"en",
")",
"{",
"if",
"(",
"en",
"!=",
"null",
")",
"{",
"int",
"toCompareValue",
";",
"if",
"(",
"en",
"instanceof",
"EnumReadable",
")",
"{",
"toCompareValue",
"=",
"(",
"(",
"EnumReadable",
")",
"en",
")",
".",
"value",
"(",
")",
";",
"}",
"else",
"{",
"toCompareValue",
"=",
"en",
".",
"ordinal",
"(",
")",
";",
"}",
"return",
"toCompareValue",
";",
"}",
"return",
"-",
"1",
";",
"}"
] | Gets the enum value.
@param en the en
@return the enum value | [
"Gets",
"the",
"enum",
"value",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L1057-L1069 |
29,223 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.readPrimitiveField | public static Object readPrimitiveField(CodedInputStream input, final WireFormat.FieldType type, boolean checkUtf8)
throws IOException {
switch (type) {
case DOUBLE:
return input.readDouble();
case FLOAT:
return input.readFloat();
case INT64:
return input.readInt64();
case UINT64:
return input.readUInt64();
case INT32:
return input.readInt32();
case FIXED64:
return input.readFixed64();
case FIXED32:
return input.readFixed32();
case BOOL:
return input.readBool();
case STRING:
if (checkUtf8) {
return input.readStringRequireUtf8();
} else {
return input.readString();
}
case BYTES:
return input.readBytes();
case UINT32:
return input.readUInt32();
case SFIXED32:
return input.readSFixed32();
case SFIXED64:
return input.readSFixed64();
case SINT32:
return input.readSInt32();
case SINT64:
return input.readSInt64();
case GROUP:
throw new IllegalArgumentException("readPrimitiveField() cannot handle nested groups.");
case MESSAGE:
throw new IllegalArgumentException("readPrimitiveField() cannot handle embedded messages.");
case ENUM:
// We don't handle enums because we don't know what to do if the
// value is not recognized.
throw new IllegalArgumentException("readPrimitiveField() cannot handle enums.");
}
throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
} | java | public static Object readPrimitiveField(CodedInputStream input, final WireFormat.FieldType type, boolean checkUtf8)
throws IOException {
switch (type) {
case DOUBLE:
return input.readDouble();
case FLOAT:
return input.readFloat();
case INT64:
return input.readInt64();
case UINT64:
return input.readUInt64();
case INT32:
return input.readInt32();
case FIXED64:
return input.readFixed64();
case FIXED32:
return input.readFixed32();
case BOOL:
return input.readBool();
case STRING:
if (checkUtf8) {
return input.readStringRequireUtf8();
} else {
return input.readString();
}
case BYTES:
return input.readBytes();
case UINT32:
return input.readUInt32();
case SFIXED32:
return input.readSFixed32();
case SFIXED64:
return input.readSFixed64();
case SINT32:
return input.readSInt32();
case SINT64:
return input.readSInt64();
case GROUP:
throw new IllegalArgumentException("readPrimitiveField() cannot handle nested groups.");
case MESSAGE:
throw new IllegalArgumentException("readPrimitiveField() cannot handle embedded messages.");
case ENUM:
// We don't handle enums because we don't know what to do if the
// value is not recognized.
throw new IllegalArgumentException("readPrimitiveField() cannot handle enums.");
}
throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
} | [
"public",
"static",
"Object",
"readPrimitiveField",
"(",
"CodedInputStream",
"input",
",",
"final",
"WireFormat",
".",
"FieldType",
"type",
",",
"boolean",
"checkUtf8",
")",
"throws",
"IOException",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"DOUBLE",
":",
"return",
"input",
".",
"readDouble",
"(",
")",
";",
"case",
"FLOAT",
":",
"return",
"input",
".",
"readFloat",
"(",
")",
";",
"case",
"INT64",
":",
"return",
"input",
".",
"readInt64",
"(",
")",
";",
"case",
"UINT64",
":",
"return",
"input",
".",
"readUInt64",
"(",
")",
";",
"case",
"INT32",
":",
"return",
"input",
".",
"readInt32",
"(",
")",
";",
"case",
"FIXED64",
":",
"return",
"input",
".",
"readFixed64",
"(",
")",
";",
"case",
"FIXED32",
":",
"return",
"input",
".",
"readFixed32",
"(",
")",
";",
"case",
"BOOL",
":",
"return",
"input",
".",
"readBool",
"(",
")",
";",
"case",
"STRING",
":",
"if",
"(",
"checkUtf8",
")",
"{",
"return",
"input",
".",
"readStringRequireUtf8",
"(",
")",
";",
"}",
"else",
"{",
"return",
"input",
".",
"readString",
"(",
")",
";",
"}",
"case",
"BYTES",
":",
"return",
"input",
".",
"readBytes",
"(",
")",
";",
"case",
"UINT32",
":",
"return",
"input",
".",
"readUInt32",
"(",
")",
";",
"case",
"SFIXED32",
":",
"return",
"input",
".",
"readSFixed32",
"(",
")",
";",
"case",
"SFIXED64",
":",
"return",
"input",
".",
"readSFixed64",
"(",
")",
";",
"case",
"SINT32",
":",
"return",
"input",
".",
"readSInt32",
"(",
")",
";",
"case",
"SINT64",
":",
"return",
"input",
".",
"readSInt64",
"(",
")",
";",
"case",
"GROUP",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"readPrimitiveField() cannot handle nested groups.\"",
")",
";",
"case",
"MESSAGE",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"readPrimitiveField() cannot handle embedded messages.\"",
")",
";",
"case",
"ENUM",
":",
"// We don't handle enums because we don't know what to do if the\r",
"// value is not recognized.\r",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"readPrimitiveField() cannot handle enums.\"",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"There is no way to get here, but the compiler thinks otherwise.\"",
")",
";",
"}"
] | Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, groups, and embedded
messages are not handled by this method.
@param input The stream from which to read.
@param type Declared type of the field.
@param checkUtf8 When true, check that the input is valid utf8.
@return An object representing the field's value, of the exact type which would be returned by
{@link Message#getField(Descriptors.FieldDescriptor)} for this field.
@throws IOException Signals that an I/O exception has occurred. | [
"Read",
"a",
"field",
"of",
"any",
"primitive",
"type",
"for",
"immutable",
"messages",
"from",
"a",
"CodedInputStream",
".",
"Enums",
"groups",
"and",
"embedded",
"messages",
"are",
"not",
"handled",
"by",
"this",
"method",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L1104-L1153 |
29,224 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.writeElement | public static void writeElement(final CodedOutputStream output, final WireFormat.FieldType type, final int number,
final Object value) throws IOException {
// Special case for groups, which need a start and end tag; other fields
// can just use writeTag() and writeFieldNoTag().
if (type == WireFormat.FieldType.GROUP) {
output.writeGroup(number, (MessageLite) value);
} else {
output.writeTag(number, getWireFormatForFieldType(type, false));
writeElementNoTag(output, type, value);
}
} | java | public static void writeElement(final CodedOutputStream output, final WireFormat.FieldType type, final int number,
final Object value) throws IOException {
// Special case for groups, which need a start and end tag; other fields
// can just use writeTag() and writeFieldNoTag().
if (type == WireFormat.FieldType.GROUP) {
output.writeGroup(number, (MessageLite) value);
} else {
output.writeTag(number, getWireFormatForFieldType(type, false));
writeElementNoTag(output, type, value);
}
} | [
"public",
"static",
"void",
"writeElement",
"(",
"final",
"CodedOutputStream",
"output",
",",
"final",
"WireFormat",
".",
"FieldType",
"type",
",",
"final",
"int",
"number",
",",
"final",
"Object",
"value",
")",
"throws",
"IOException",
"{",
"// Special case for groups, which need a start and end tag; other fields\r",
"// can just use writeTag() and writeFieldNoTag().\r",
"if",
"(",
"type",
"==",
"WireFormat",
".",
"FieldType",
".",
"GROUP",
")",
"{",
"output",
".",
"writeGroup",
"(",
"number",
",",
"(",
"MessageLite",
")",
"value",
")",
";",
"}",
"else",
"{",
"output",
".",
"writeTag",
"(",
"number",
",",
"getWireFormatForFieldType",
"(",
"type",
",",
"false",
")",
")",
";",
"writeElementNoTag",
"(",
"output",
",",
"type",
",",
"value",
")",
";",
"}",
"}"
] | Write a single tag-value pair to the stream.
@param output The output stream.
@param type The field's type.
@param number The field's number.
@param value Object representing the field's value. Must be of the exact type which would be returned by
{@link Message#getField(Descriptors.FieldDescriptor)} for this field.
@throws IOException Signals that an I/O exception has occurred. | [
"Write",
"a",
"single",
"tag",
"-",
"value",
"pair",
"to",
"the",
"stream",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L1165-L1175 |
29,225 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.getWireFormatForFieldType | static int getWireFormatForFieldType(final WireFormat.FieldType type, boolean isPacked) {
if (isPacked) {
return WireFormat.WIRETYPE_LENGTH_DELIMITED;
} else {
return type.getWireType();
}
} | java | static int getWireFormatForFieldType(final WireFormat.FieldType type, boolean isPacked) {
if (isPacked) {
return WireFormat.WIRETYPE_LENGTH_DELIMITED;
} else {
return type.getWireType();
}
} | [
"static",
"int",
"getWireFormatForFieldType",
"(",
"final",
"WireFormat",
".",
"FieldType",
"type",
",",
"boolean",
"isPacked",
")",
"{",
"if",
"(",
"isPacked",
")",
"{",
"return",
"WireFormat",
".",
"WIRETYPE_LENGTH_DELIMITED",
";",
"}",
"else",
"{",
"return",
"type",
".",
"getWireType",
"(",
")",
";",
"}",
"}"
] | Given a field type, return the wire type.
@param type the type
@param isPacked the is packed
@return the wire format for field type
@returns One of the {@code WIRETYPE_} constants defined in {@link WireFormat}. | [
"Given",
"a",
"field",
"type",
"return",
"the",
"wire",
"type",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L1185-L1191 |
29,226 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.computeElementSizeNoTag | public static int computeElementSizeNoTag(final WireFormat.FieldType type, final Object value) {
switch (type) {
// Note: Minor violation of 80-char limit rule here because this would
// actually be harder to read if we wrapped the lines.
case DOUBLE:
return CodedOutputStream.computeDoubleSizeNoTag((Double) value);
case FLOAT:
return CodedOutputStream.computeFloatSizeNoTag((Float) value);
case INT64:
return CodedOutputStream.computeInt64SizeNoTag((Long) value);
case UINT64:
return CodedOutputStream.computeUInt64SizeNoTag((Long) value);
case INT32:
return CodedOutputStream.computeInt32SizeNoTag((Integer) value);
case FIXED64:
return CodedOutputStream.computeFixed64SizeNoTag((Long) value);
case FIXED32:
return CodedOutputStream.computeFixed32SizeNoTag((Integer) value);
case BOOL:
return CodedOutputStream.computeBoolSizeNoTag((Boolean) value);
case STRING:
return CodedOutputStream.computeStringSizeNoTag((String) value);
case GROUP:
return CodedOutputStream.computeGroupSizeNoTag((MessageLite) value);
case BYTES:
if (value instanceof ByteString) {
return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
} else {
return CodedOutputStream.computeByteArraySizeNoTag((byte[]) value);
}
case UINT32:
return CodedOutputStream.computeUInt32SizeNoTag((Integer) value);
case SFIXED32:
return CodedOutputStream.computeSFixed32SizeNoTag((Integer) value);
case SFIXED64:
return CodedOutputStream.computeSFixed64SizeNoTag((Long) value);
case SINT32:
return CodedOutputStream.computeSInt32SizeNoTag((Integer) value);
case SINT64:
return CodedOutputStream.computeSInt64SizeNoTag((Long) value);
case MESSAGE:
if (value instanceof LazyField) {
return CodedOutputStream.computeLazyFieldSizeNoTag((LazyField) value);
} else {
return computeObjectSizeNoTag(value);
}
case ENUM:
if (value instanceof Internal.EnumLite) {
return CodedOutputStream.computeEnumSizeNoTag(((Internal.EnumLite) value).getNumber());
} else {
if (value instanceof EnumReadable) {
return CodedOutputStream.computeEnumSizeNoTag(((EnumReadable) value).value());
} else if (value instanceof Enum) {
return CodedOutputStream.computeEnumSizeNoTag(((Enum) value).ordinal());
}
return CodedOutputStream.computeEnumSizeNoTag((Integer) value);
}
}
throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
} | java | public static int computeElementSizeNoTag(final WireFormat.FieldType type, final Object value) {
switch (type) {
// Note: Minor violation of 80-char limit rule here because this would
// actually be harder to read if we wrapped the lines.
case DOUBLE:
return CodedOutputStream.computeDoubleSizeNoTag((Double) value);
case FLOAT:
return CodedOutputStream.computeFloatSizeNoTag((Float) value);
case INT64:
return CodedOutputStream.computeInt64SizeNoTag((Long) value);
case UINT64:
return CodedOutputStream.computeUInt64SizeNoTag((Long) value);
case INT32:
return CodedOutputStream.computeInt32SizeNoTag((Integer) value);
case FIXED64:
return CodedOutputStream.computeFixed64SizeNoTag((Long) value);
case FIXED32:
return CodedOutputStream.computeFixed32SizeNoTag((Integer) value);
case BOOL:
return CodedOutputStream.computeBoolSizeNoTag((Boolean) value);
case STRING:
return CodedOutputStream.computeStringSizeNoTag((String) value);
case GROUP:
return CodedOutputStream.computeGroupSizeNoTag((MessageLite) value);
case BYTES:
if (value instanceof ByteString) {
return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
} else {
return CodedOutputStream.computeByteArraySizeNoTag((byte[]) value);
}
case UINT32:
return CodedOutputStream.computeUInt32SizeNoTag((Integer) value);
case SFIXED32:
return CodedOutputStream.computeSFixed32SizeNoTag((Integer) value);
case SFIXED64:
return CodedOutputStream.computeSFixed64SizeNoTag((Long) value);
case SINT32:
return CodedOutputStream.computeSInt32SizeNoTag((Integer) value);
case SINT64:
return CodedOutputStream.computeSInt64SizeNoTag((Long) value);
case MESSAGE:
if (value instanceof LazyField) {
return CodedOutputStream.computeLazyFieldSizeNoTag((LazyField) value);
} else {
return computeObjectSizeNoTag(value);
}
case ENUM:
if (value instanceof Internal.EnumLite) {
return CodedOutputStream.computeEnumSizeNoTag(((Internal.EnumLite) value).getNumber());
} else {
if (value instanceof EnumReadable) {
return CodedOutputStream.computeEnumSizeNoTag(((EnumReadable) value).value());
} else if (value instanceof Enum) {
return CodedOutputStream.computeEnumSizeNoTag(((Enum) value).ordinal());
}
return CodedOutputStream.computeEnumSizeNoTag((Integer) value);
}
}
throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
} | [
"public",
"static",
"int",
"computeElementSizeNoTag",
"(",
"final",
"WireFormat",
".",
"FieldType",
"type",
",",
"final",
"Object",
"value",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"// Note: Minor violation of 80-char limit rule here because this would\r",
"// actually be harder to read if we wrapped the lines.\r",
"case",
"DOUBLE",
":",
"return",
"CodedOutputStream",
".",
"computeDoubleSizeNoTag",
"(",
"(",
"Double",
")",
"value",
")",
";",
"case",
"FLOAT",
":",
"return",
"CodedOutputStream",
".",
"computeFloatSizeNoTag",
"(",
"(",
"Float",
")",
"value",
")",
";",
"case",
"INT64",
":",
"return",
"CodedOutputStream",
".",
"computeInt64SizeNoTag",
"(",
"(",
"Long",
")",
"value",
")",
";",
"case",
"UINT64",
":",
"return",
"CodedOutputStream",
".",
"computeUInt64SizeNoTag",
"(",
"(",
"Long",
")",
"value",
")",
";",
"case",
"INT32",
":",
"return",
"CodedOutputStream",
".",
"computeInt32SizeNoTag",
"(",
"(",
"Integer",
")",
"value",
")",
";",
"case",
"FIXED64",
":",
"return",
"CodedOutputStream",
".",
"computeFixed64SizeNoTag",
"(",
"(",
"Long",
")",
"value",
")",
";",
"case",
"FIXED32",
":",
"return",
"CodedOutputStream",
".",
"computeFixed32SizeNoTag",
"(",
"(",
"Integer",
")",
"value",
")",
";",
"case",
"BOOL",
":",
"return",
"CodedOutputStream",
".",
"computeBoolSizeNoTag",
"(",
"(",
"Boolean",
")",
"value",
")",
";",
"case",
"STRING",
":",
"return",
"CodedOutputStream",
".",
"computeStringSizeNoTag",
"(",
"(",
"String",
")",
"value",
")",
";",
"case",
"GROUP",
":",
"return",
"CodedOutputStream",
".",
"computeGroupSizeNoTag",
"(",
"(",
"MessageLite",
")",
"value",
")",
";",
"case",
"BYTES",
":",
"if",
"(",
"value",
"instanceof",
"ByteString",
")",
"{",
"return",
"CodedOutputStream",
".",
"computeBytesSizeNoTag",
"(",
"(",
"ByteString",
")",
"value",
")",
";",
"}",
"else",
"{",
"return",
"CodedOutputStream",
".",
"computeByteArraySizeNoTag",
"(",
"(",
"byte",
"[",
"]",
")",
"value",
")",
";",
"}",
"case",
"UINT32",
":",
"return",
"CodedOutputStream",
".",
"computeUInt32SizeNoTag",
"(",
"(",
"Integer",
")",
"value",
")",
";",
"case",
"SFIXED32",
":",
"return",
"CodedOutputStream",
".",
"computeSFixed32SizeNoTag",
"(",
"(",
"Integer",
")",
"value",
")",
";",
"case",
"SFIXED64",
":",
"return",
"CodedOutputStream",
".",
"computeSFixed64SizeNoTag",
"(",
"(",
"Long",
")",
"value",
")",
";",
"case",
"SINT32",
":",
"return",
"CodedOutputStream",
".",
"computeSInt32SizeNoTag",
"(",
"(",
"Integer",
")",
"value",
")",
";",
"case",
"SINT64",
":",
"return",
"CodedOutputStream",
".",
"computeSInt64SizeNoTag",
"(",
"(",
"Long",
")",
"value",
")",
";",
"case",
"MESSAGE",
":",
"if",
"(",
"value",
"instanceof",
"LazyField",
")",
"{",
"return",
"CodedOutputStream",
".",
"computeLazyFieldSizeNoTag",
"(",
"(",
"LazyField",
")",
"value",
")",
";",
"}",
"else",
"{",
"return",
"computeObjectSizeNoTag",
"(",
"value",
")",
";",
"}",
"case",
"ENUM",
":",
"if",
"(",
"value",
"instanceof",
"Internal",
".",
"EnumLite",
")",
"{",
"return",
"CodedOutputStream",
".",
"computeEnumSizeNoTag",
"(",
"(",
"(",
"Internal",
".",
"EnumLite",
")",
"value",
")",
".",
"getNumber",
"(",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"value",
"instanceof",
"EnumReadable",
")",
"{",
"return",
"CodedOutputStream",
".",
"computeEnumSizeNoTag",
"(",
"(",
"(",
"EnumReadable",
")",
"value",
")",
".",
"value",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"value",
"instanceof",
"Enum",
")",
"{",
"return",
"CodedOutputStream",
".",
"computeEnumSizeNoTag",
"(",
"(",
"(",
"Enum",
")",
"value",
")",
".",
"ordinal",
"(",
")",
")",
";",
"}",
"return",
"CodedOutputStream",
".",
"computeEnumSizeNoTag",
"(",
"(",
"Integer",
")",
"value",
")",
";",
"}",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"There is no way to get here, but the compiler thinks otherwise.\"",
")",
";",
"}"
] | Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.
@param type The field's type.
@param value Object representing the field's value. Must be of the exact type which would be returned by
{@link Message#getField(Descriptors.FieldDescriptor)} for this field.
@return the int | [
"Compute",
"the",
"number",
"of",
"bytes",
"that",
"would",
"be",
"needed",
"to",
"encode",
"a",
"particular",
"value",
"of",
"arbitrary",
"type",
"excluding",
"tag",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L1296-L1359 |
29,227 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java | CodedConstant.getMapKVMessageElements | private static MessageElement getMapKVMessageElements(String name, MapType mapType) {
MessageElement.Builder ret = MessageElement.builder();
ret.name(name);
DataType keyType = mapType.keyType();
Builder fieldBuilder = FieldElement.builder().name("key").tag(1);
fieldBuilder.type(keyType).label(FieldElement.Label.OPTIONAL);
ret.addField(fieldBuilder.build());
DataType valueType = mapType.valueType();
fieldBuilder = FieldElement.builder().name("value").tag(2);
fieldBuilder.type(valueType).label(FieldElement.Label.OPTIONAL);
ret.addField(fieldBuilder.build());
return ret.build();
} | java | private static MessageElement getMapKVMessageElements(String name, MapType mapType) {
MessageElement.Builder ret = MessageElement.builder();
ret.name(name);
DataType keyType = mapType.keyType();
Builder fieldBuilder = FieldElement.builder().name("key").tag(1);
fieldBuilder.type(keyType).label(FieldElement.Label.OPTIONAL);
ret.addField(fieldBuilder.build());
DataType valueType = mapType.valueType();
fieldBuilder = FieldElement.builder().name("value").tag(2);
fieldBuilder.type(valueType).label(FieldElement.Label.OPTIONAL);
ret.addField(fieldBuilder.build());
return ret.build();
} | [
"private",
"static",
"MessageElement",
"getMapKVMessageElements",
"(",
"String",
"name",
",",
"MapType",
"mapType",
")",
"{",
"MessageElement",
".",
"Builder",
"ret",
"=",
"MessageElement",
".",
"builder",
"(",
")",
";",
"ret",
".",
"name",
"(",
"name",
")",
";",
"DataType",
"keyType",
"=",
"mapType",
".",
"keyType",
"(",
")",
";",
"Builder",
"fieldBuilder",
"=",
"FieldElement",
".",
"builder",
"(",
")",
".",
"name",
"(",
"\"key\"",
")",
".",
"tag",
"(",
"1",
")",
";",
"fieldBuilder",
".",
"type",
"(",
"keyType",
")",
".",
"label",
"(",
"FieldElement",
".",
"Label",
".",
"OPTIONAL",
")",
";",
"ret",
".",
"addField",
"(",
"fieldBuilder",
".",
"build",
"(",
")",
")",
";",
"DataType",
"valueType",
"=",
"mapType",
".",
"valueType",
"(",
")",
";",
"fieldBuilder",
"=",
"FieldElement",
".",
"builder",
"(",
")",
".",
"name",
"(",
"\"value\"",
")",
".",
"tag",
"(",
"2",
")",
";",
"fieldBuilder",
".",
"type",
"(",
"valueType",
")",
".",
"label",
"(",
"FieldElement",
".",
"Label",
".",
"OPTIONAL",
")",
";",
"ret",
".",
"addField",
"(",
"fieldBuilder",
".",
"build",
"(",
")",
")",
";",
"return",
"ret",
".",
"build",
"(",
")",
";",
"}"
] | Gets the map kv message elements.
@param name the name
@param mapType the map type
@return the map kv message elements | [
"Gets",
"the",
"map",
"kv",
"message",
"elements",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodedConstant.java#L1567-L1582 |
29,228 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/IDLProxyObject.java | IDLProxyObject.doGetFieldValue | private Object doGetFieldValue(String fullField, String field, Object object, boolean useCache,
Map<String, ReflectInfo> cachedFields) {
// check cache
Field f;
if (useCache) {
ReflectInfo info = cachedFields.get(fullField);
if (info != null) {
return getField(info.target, info.field);
}
}
int index = field.indexOf('.');
if (index != -1) {
String parent = field.substring(0, index);
String sub = field.substring(index + 1);
try {
f = FieldUtils.findField(object.getClass(), parent);
if (f == null) {
throw new RuntimeException(
"No field '" + parent + "' found at class " + object.getClass().getName());
}
f.setAccessible(true);
Object o = f.get(object);
if (o == null) {
return null;
}
return get(fullField, sub, o);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
f = FieldUtils.findField(object.getClass(), field);
if (f == null) {
throw new RuntimeException("No field '" + field + "' found at class " + object.getClass().getName());
}
if (useCache && !cachedFields.containsKey(fullField)) {
cachedFields.put(fullField, new ReflectInfo(f, object));
}
return getField(object, f);
} | java | private Object doGetFieldValue(String fullField, String field, Object object, boolean useCache,
Map<String, ReflectInfo> cachedFields) {
// check cache
Field f;
if (useCache) {
ReflectInfo info = cachedFields.get(fullField);
if (info != null) {
return getField(info.target, info.field);
}
}
int index = field.indexOf('.');
if (index != -1) {
String parent = field.substring(0, index);
String sub = field.substring(index + 1);
try {
f = FieldUtils.findField(object.getClass(), parent);
if (f == null) {
throw new RuntimeException(
"No field '" + parent + "' found at class " + object.getClass().getName());
}
f.setAccessible(true);
Object o = f.get(object);
if (o == null) {
return null;
}
return get(fullField, sub, o);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
f = FieldUtils.findField(object.getClass(), field);
if (f == null) {
throw new RuntimeException("No field '" + field + "' found at class " + object.getClass().getName());
}
if (useCache && !cachedFields.containsKey(fullField)) {
cachedFields.put(fullField, new ReflectInfo(f, object));
}
return getField(object, f);
} | [
"private",
"Object",
"doGetFieldValue",
"(",
"String",
"fullField",
",",
"String",
"field",
",",
"Object",
"object",
",",
"boolean",
"useCache",
",",
"Map",
"<",
"String",
",",
"ReflectInfo",
">",
"cachedFields",
")",
"{",
"// check cache",
"Field",
"f",
";",
"if",
"(",
"useCache",
")",
"{",
"ReflectInfo",
"info",
"=",
"cachedFields",
".",
"get",
"(",
"fullField",
")",
";",
"if",
"(",
"info",
"!=",
"null",
")",
"{",
"return",
"getField",
"(",
"info",
".",
"target",
",",
"info",
".",
"field",
")",
";",
"}",
"}",
"int",
"index",
"=",
"field",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"index",
"!=",
"-",
"1",
")",
"{",
"String",
"parent",
"=",
"field",
".",
"substring",
"(",
"0",
",",
"index",
")",
";",
"String",
"sub",
"=",
"field",
".",
"substring",
"(",
"index",
"+",
"1",
")",
";",
"try",
"{",
"f",
"=",
"FieldUtils",
".",
"findField",
"(",
"object",
".",
"getClass",
"(",
")",
",",
"parent",
")",
";",
"if",
"(",
"f",
"==",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"No field '\"",
"+",
"parent",
"+",
"\"' found at class \"",
"+",
"object",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"f",
".",
"setAccessible",
"(",
"true",
")",
";",
"Object",
"o",
"=",
"f",
".",
"get",
"(",
"object",
")",
";",
"if",
"(",
"o",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"get",
"(",
"fullField",
",",
"sub",
",",
"o",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"}",
"f",
"=",
"FieldUtils",
".",
"findField",
"(",
"object",
".",
"getClass",
"(",
")",
",",
"field",
")",
";",
"if",
"(",
"f",
"==",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"No field '\"",
"+",
"field",
"+",
"\"' found at class \"",
"+",
"object",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"useCache",
"&&",
"!",
"cachedFields",
".",
"containsKey",
"(",
"fullField",
")",
")",
"{",
"cachedFields",
".",
"put",
"(",
"fullField",
",",
"new",
"ReflectInfo",
"(",
"f",
",",
"object",
")",
")",
";",
"}",
"return",
"getField",
"(",
"object",
",",
"f",
")",
";",
"}"
] | Do get field value.
@param fullField the full field
@param field the field
@param object the object
@param useCache the use cache
@param cachedFields the cached fields
@return the object | [
"Do",
"get",
"field",
"value",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/IDLProxyObject.java#L249-L290 |
29,229 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufProxy.java | ProtobufProxy.isDebugEnabled | public static boolean isDebugEnabled() {
String debugEnv = System.getenv(DEBUG_CONTROL);
if (debugEnv != null && Boolean.parseBoolean(debugEnv)) {
return true;
}
Boolean debug = DEBUG_CONTROLLER.get();
if (debug == null) {
debug = false; // set default to close debug info
}
return debug;
} | java | public static boolean isDebugEnabled() {
String debugEnv = System.getenv(DEBUG_CONTROL);
if (debugEnv != null && Boolean.parseBoolean(debugEnv)) {
return true;
}
Boolean debug = DEBUG_CONTROLLER.get();
if (debug == null) {
debug = false; // set default to close debug info
}
return debug;
} | [
"public",
"static",
"boolean",
"isDebugEnabled",
"(",
")",
"{",
"String",
"debugEnv",
"=",
"System",
".",
"getenv",
"(",
"DEBUG_CONTROL",
")",
";",
"if",
"(",
"debugEnv",
"!=",
"null",
"&&",
"Boolean",
".",
"parseBoolean",
"(",
"debugEnv",
")",
")",
"{",
"return",
"true",
";",
"}",
"Boolean",
"debug",
"=",
"DEBUG_CONTROLLER",
".",
"get",
"(",
")",
";",
"if",
"(",
"debug",
"==",
"null",
")",
"{",
"debug",
"=",
"false",
";",
"// set default to close debug info",
"}",
"return",
"debug",
";",
"}"
] | Checks if is debug enabled.
@return true, if is debug enabled | [
"Checks",
"if",
"is",
"debug",
"enabled",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufProxy.java#L109-L121 |
29,230 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufProxy.java | ProtobufProxy.getCodeGenerator | private static ICodeGenerator getCodeGenerator(Class cls) {
// check if has default constructor
if (!cls.isMemberClass()) {
try {
cls.getConstructor(new Class<?>[0]);
} catch (NoSuchMethodException e2) {
throw new IllegalArgumentException(
"Class '" + cls.getName() + "' must has default constructor method with no parameters.", e2);
} catch (SecurityException e2) {
throw new IllegalArgumentException(e2.getMessage(), e2);
}
}
ICodeGenerator cg = new TemplateCodeGenerator(cls);
return cg;
} | java | private static ICodeGenerator getCodeGenerator(Class cls) {
// check if has default constructor
if (!cls.isMemberClass()) {
try {
cls.getConstructor(new Class<?>[0]);
} catch (NoSuchMethodException e2) {
throw new IllegalArgumentException(
"Class '" + cls.getName() + "' must has default constructor method with no parameters.", e2);
} catch (SecurityException e2) {
throw new IllegalArgumentException(e2.getMessage(), e2);
}
}
ICodeGenerator cg = new TemplateCodeGenerator(cls);
return cg;
} | [
"private",
"static",
"ICodeGenerator",
"getCodeGenerator",
"(",
"Class",
"cls",
")",
"{",
"// check if has default constructor",
"if",
"(",
"!",
"cls",
".",
"isMemberClass",
"(",
")",
")",
"{",
"try",
"{",
"cls",
".",
"getConstructor",
"(",
"new",
"Class",
"<",
"?",
">",
"[",
"0",
"]",
")",
";",
"}",
"catch",
"(",
"NoSuchMethodException",
"e2",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Class '\"",
"+",
"cls",
".",
"getName",
"(",
")",
"+",
"\"' must has default constructor method with no parameters.\"",
",",
"e2",
")",
";",
"}",
"catch",
"(",
"SecurityException",
"e2",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"e2",
".",
"getMessage",
"(",
")",
",",
"e2",
")",
";",
"}",
"}",
"ICodeGenerator",
"cg",
"=",
"new",
"TemplateCodeGenerator",
"(",
"cls",
")",
";",
"return",
"cg",
";",
"}"
] | Gets the code generator.
@param cls the cls
@return the code generator | [
"Gets",
"the",
"code",
"generator",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufProxy.java#L166-L183 |
29,231 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ClassHelper.java | ClassHelper.getClassLoader | public static ClassLoader getClassLoader(Class<?> cls) {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (Throwable ex) {
// Cannot access thread context ClassLoader - falling back to system
// class loader...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
cl = cls.getClassLoader();
}
return cl;
} | java | public static ClassLoader getClassLoader(Class<?> cls) {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (Throwable ex) {
// Cannot access thread context ClassLoader - falling back to system
// class loader...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
cl = cls.getClassLoader();
}
return cl;
} | [
"public",
"static",
"ClassLoader",
"getClassLoader",
"(",
"Class",
"<",
"?",
">",
"cls",
")",
"{",
"ClassLoader",
"cl",
"=",
"null",
";",
"try",
"{",
"cl",
"=",
"Thread",
".",
"currentThread",
"(",
")",
".",
"getContextClassLoader",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"ex",
")",
"{",
"// Cannot access thread context ClassLoader - falling back to system\r",
"// class loader...\r",
"}",
"if",
"(",
"cl",
"==",
"null",
")",
"{",
"// No thread context class loader -> use class loader of this class.\r",
"cl",
"=",
"cls",
".",
"getClassLoader",
"(",
")",
";",
"}",
"return",
"cl",
";",
"}"
] | get class loader
@param cls target class to get ownered class loader
@return class loader | [
"get",
"class",
"loader"
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/ClassHelper.java#L118-L131 |
29,232 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntry.java | MapEntry.newDefaultInstance | public static <K, V> MapEntry<K, V> newDefaultInstance(Descriptor descriptor, WireFormat.FieldType keyType,
K defaultKey, WireFormat.FieldType valueType, V defaultValue) {
return new MapEntry<K, V>(descriptor, keyType, defaultKey, valueType, defaultValue);
} | java | public static <K, V> MapEntry<K, V> newDefaultInstance(Descriptor descriptor, WireFormat.FieldType keyType,
K defaultKey, WireFormat.FieldType valueType, V defaultValue) {
return new MapEntry<K, V>(descriptor, keyType, defaultKey, valueType, defaultValue);
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"MapEntry",
"<",
"K",
",",
"V",
">",
"newDefaultInstance",
"(",
"Descriptor",
"descriptor",
",",
"WireFormat",
".",
"FieldType",
"keyType",
",",
"K",
"defaultKey",
",",
"WireFormat",
".",
"FieldType",
"valueType",
",",
"V",
"defaultValue",
")",
"{",
"return",
"new",
"MapEntry",
"<",
"K",
",",
"V",
">",
"(",
"descriptor",
",",
"keyType",
",",
"defaultKey",
",",
"valueType",
",",
"defaultValue",
")",
";",
"}"
] | Create a default MapEntry instance. A default MapEntry instance should be created only once for each map entry
message type. Generated code should store the created default instance and use it later to create new MapEntry
messages of the same type.
@param <K> the key type
@param <V> the value type
@param descriptor the descriptor
@param keyType the key type
@param defaultKey the default key
@param valueType the value type
@param defaultValue the default value
@return the map entry | [
"Create",
"a",
"default",
"MapEntry",
"instance",
".",
"A",
"default",
"MapEntry",
"instance",
"should",
"be",
"created",
"only",
"once",
"for",
"each",
"map",
"entry",
"message",
"type",
".",
"Generated",
"code",
"should",
"store",
"the",
"created",
"default",
"instance",
"and",
"use",
"it",
"later",
"to",
"create",
"new",
"MapEntry",
"messages",
"of",
"the",
"same",
"type",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntry.java#L161-L164 |
29,233 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntry.java | MapEntry.checkFieldDescriptor | private void checkFieldDescriptor(FieldDescriptor field) {
if (field.getContainingType() != metadata.descriptor) {
throw new RuntimeException("Wrong FieldDescriptor \"" + field.getFullName() + "\" used in message \""
+ metadata.descriptor.getFullName());
}
} | java | private void checkFieldDescriptor(FieldDescriptor field) {
if (field.getContainingType() != metadata.descriptor) {
throw new RuntimeException("Wrong FieldDescriptor \"" + field.getFullName() + "\" used in message \""
+ metadata.descriptor.getFullName());
}
} | [
"private",
"void",
"checkFieldDescriptor",
"(",
"FieldDescriptor",
"field",
")",
"{",
"if",
"(",
"field",
".",
"getContainingType",
"(",
")",
"!=",
"metadata",
".",
"descriptor",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Wrong FieldDescriptor \\\"\"",
"+",
"field",
".",
"getFullName",
"(",
")",
"+",
"\"\\\" used in message \\\"\"",
"+",
"metadata",
".",
"descriptor",
".",
"getFullName",
"(",
")",
")",
";",
"}",
"}"
] | Check field descriptor.
@param field the field | [
"Check",
"field",
"descriptor",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapEntry.java#L276-L281 |
29,234 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java | MapField.emptyMapField | public static <K, V> MapField<K, V> emptyMapField(MapEntry<K, V> defaultEntry) {
return new MapField<K, V>(defaultEntry, StorageMode.MAP, Collections.<K, V> emptyMap(), null);
} | java | public static <K, V> MapField<K, V> emptyMapField(MapEntry<K, V> defaultEntry) {
return new MapField<K, V>(defaultEntry, StorageMode.MAP, Collections.<K, V> emptyMap(), null);
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"MapField",
"<",
"K",
",",
"V",
">",
"emptyMapField",
"(",
"MapEntry",
"<",
"K",
",",
"V",
">",
"defaultEntry",
")",
"{",
"return",
"new",
"MapField",
"<",
"K",
",",
"V",
">",
"(",
"defaultEntry",
",",
"StorageMode",
".",
"MAP",
",",
"Collections",
".",
"<",
"K",
",",
"V",
">",
"emptyMap",
"(",
")",
",",
"null",
")",
";",
"}"
] | Returns an immutable empty MapField. | [
"Returns",
"an",
"immutable",
"empty",
"MapField",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java#L118-L120 |
29,235 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java | MapField.newMapField | public static <K, V> MapField<K, V> newMapField(MapEntry<K, V> defaultEntry) {
return new MapField<K, V>(defaultEntry, StorageMode.MAP, new HashMap<K, V>(), null);
} | java | public static <K, V> MapField<K, V> newMapField(MapEntry<K, V> defaultEntry) {
return new MapField<K, V>(defaultEntry, StorageMode.MAP, new HashMap<K, V>(), null);
} | [
"public",
"static",
"<",
"K",
",",
"V",
">",
"MapField",
"<",
"K",
",",
"V",
">",
"newMapField",
"(",
"MapEntry",
"<",
"K",
",",
"V",
">",
"defaultEntry",
")",
"{",
"return",
"new",
"MapField",
"<",
"K",
",",
"V",
">",
"(",
"defaultEntry",
",",
"StorageMode",
".",
"MAP",
",",
"new",
"HashMap",
"<",
"K",
",",
"V",
">",
"(",
")",
",",
"null",
")",
";",
"}"
] | Creates a new mutable empty MapField. | [
"Creates",
"a",
"new",
"mutable",
"empty",
"MapField",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java#L123-L125 |
29,236 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java | MapField.getMap | public Map<K, V> getMap() {
if (mode == StorageMode.LIST) {
synchronized (this) {
if (mode == StorageMode.LIST) {
mapData = convertListToMap(listData);
mode = StorageMode.BOTH;
}
}
}
return Collections.unmodifiableMap(mapData);
} | java | public Map<K, V> getMap() {
if (mode == StorageMode.LIST) {
synchronized (this) {
if (mode == StorageMode.LIST) {
mapData = convertListToMap(listData);
mode = StorageMode.BOTH;
}
}
}
return Collections.unmodifiableMap(mapData);
} | [
"public",
"Map",
"<",
"K",
",",
"V",
">",
"getMap",
"(",
")",
"{",
"if",
"(",
"mode",
"==",
"StorageMode",
".",
"LIST",
")",
"{",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"mode",
"==",
"StorageMode",
".",
"LIST",
")",
"{",
"mapData",
"=",
"convertListToMap",
"(",
"listData",
")",
";",
"mode",
"=",
"StorageMode",
".",
"BOTH",
";",
"}",
"}",
"}",
"return",
"Collections",
".",
"unmodifiableMap",
"(",
"mapData",
")",
";",
"}"
] | Returns the content of this MapField as a read-only Map. | [
"Returns",
"the",
"content",
"of",
"this",
"MapField",
"as",
"a",
"read",
"-",
"only",
"Map",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java#L153-L163 |
29,237 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java | MapField.getMutableMap | public Map<K, V> getMutableMap() {
if (mode != StorageMode.MAP) {
if (mode == StorageMode.LIST) {
mapData = convertListToMap(listData);
}
listData = null;
mode = StorageMode.MAP;
}
return mapData;
} | java | public Map<K, V> getMutableMap() {
if (mode != StorageMode.MAP) {
if (mode == StorageMode.LIST) {
mapData = convertListToMap(listData);
}
listData = null;
mode = StorageMode.MAP;
}
return mapData;
} | [
"public",
"Map",
"<",
"K",
",",
"V",
">",
"getMutableMap",
"(",
")",
"{",
"if",
"(",
"mode",
"!=",
"StorageMode",
".",
"MAP",
")",
"{",
"if",
"(",
"mode",
"==",
"StorageMode",
".",
"LIST",
")",
"{",
"mapData",
"=",
"convertListToMap",
"(",
"listData",
")",
";",
"}",
"listData",
"=",
"null",
";",
"mode",
"=",
"StorageMode",
".",
"MAP",
";",
"}",
"return",
"mapData",
";",
"}"
] | Gets a mutable Map view of this MapField. | [
"Gets",
"a",
"mutable",
"Map",
"view",
"of",
"this",
"MapField",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java#L166-L175 |
29,238 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java | MapField.copy | public MapField<K, V> copy() {
return new MapField<K, V>(converter, StorageMode.MAP, MapFieldLite.copy(getMap()), null);
} | java | public MapField<K, V> copy() {
return new MapField<K, V>(converter, StorageMode.MAP, MapFieldLite.copy(getMap()), null);
} | [
"public",
"MapField",
"<",
"K",
",",
"V",
">",
"copy",
"(",
")",
"{",
"return",
"new",
"MapField",
"<",
"K",
",",
"V",
">",
"(",
"converter",
",",
"StorageMode",
".",
"MAP",
",",
"MapFieldLite",
".",
"copy",
"(",
"getMap",
"(",
")",
")",
",",
"null",
")",
";",
"}"
] | Returns a deep copy of this MapField. | [
"Returns",
"a",
"deep",
"copy",
"of",
"this",
"MapField",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java#L202-L204 |
29,239 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java | MapField.getList | List<Message> getList() {
if (mode == StorageMode.MAP) {
synchronized (this) {
if (mode == StorageMode.MAP) {
listData = convertMapToList(mapData);
mode = StorageMode.BOTH;
}
}
}
return Collections.unmodifiableList(listData);
} | java | List<Message> getList() {
if (mode == StorageMode.MAP) {
synchronized (this) {
if (mode == StorageMode.MAP) {
listData = convertMapToList(mapData);
mode = StorageMode.BOTH;
}
}
}
return Collections.unmodifiableList(listData);
} | [
"List",
"<",
"Message",
">",
"getList",
"(",
")",
"{",
"if",
"(",
"mode",
"==",
"StorageMode",
".",
"MAP",
")",
"{",
"synchronized",
"(",
"this",
")",
"{",
"if",
"(",
"mode",
"==",
"StorageMode",
".",
"MAP",
")",
"{",
"listData",
"=",
"convertMapToList",
"(",
"mapData",
")",
";",
"mode",
"=",
"StorageMode",
".",
"BOTH",
";",
"}",
"}",
"}",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"listData",
")",
";",
"}"
] | Gets the content of this MapField as a read-only List. | [
"Gets",
"the",
"content",
"of",
"this",
"MapField",
"as",
"a",
"read",
"-",
"only",
"List",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java#L207-L217 |
29,240 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java | MapField.getMutableList | List<Message> getMutableList() {
if (mode != StorageMode.LIST) {
if (mode == StorageMode.MAP) {
listData = convertMapToList(mapData);
}
mapData = null;
mode = StorageMode.LIST;
}
return listData;
} | java | List<Message> getMutableList() {
if (mode != StorageMode.LIST) {
if (mode == StorageMode.MAP) {
listData = convertMapToList(mapData);
}
mapData = null;
mode = StorageMode.LIST;
}
return listData;
} | [
"List",
"<",
"Message",
">",
"getMutableList",
"(",
")",
"{",
"if",
"(",
"mode",
"!=",
"StorageMode",
".",
"LIST",
")",
"{",
"if",
"(",
"mode",
"==",
"StorageMode",
".",
"MAP",
")",
"{",
"listData",
"=",
"convertMapToList",
"(",
"mapData",
")",
";",
"}",
"mapData",
"=",
"null",
";",
"mode",
"=",
"StorageMode",
".",
"LIST",
";",
"}",
"return",
"listData",
";",
"}"
] | Gets a mutable List view of this MapField. | [
"Gets",
"a",
"mutable",
"List",
"view",
"of",
"this",
"MapField",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapField.java#L220-L229 |
29,241 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java | CodeGenerator.genImportCode | private void genImportCode(StringBuilder code) {
code.append("import com.google.protobuf.*").append(JAVA_LINE_BREAK);
code.append("import java.io.IOException").append(JAVA_LINE_BREAK);
code.append("import com.baidu.bjf.remoting.protobuf.utils.*").append(JAVA_LINE_BREAK);
code.append("import com.baidu.bjf.remoting.protobuf.code.*").append(JAVA_LINE_BREAK);
code.append("import java.lang.reflect.*").append(JAVA_LINE_BREAK);
code.append("import com.baidu.bjf.remoting.protobuf.*").append(JAVA_LINE_BREAK);
code.append("import java.util.*").append(JAVA_LINE_BREAK);
if (!StringUtils.isEmpty(getPackage())) {
code.append("import ").append(ClassHelper.getInternalName(cls.getCanonicalName())).append(JAVA_LINE_BREAK);
}
} | java | private void genImportCode(StringBuilder code) {
code.append("import com.google.protobuf.*").append(JAVA_LINE_BREAK);
code.append("import java.io.IOException").append(JAVA_LINE_BREAK);
code.append("import com.baidu.bjf.remoting.protobuf.utils.*").append(JAVA_LINE_BREAK);
code.append("import com.baidu.bjf.remoting.protobuf.code.*").append(JAVA_LINE_BREAK);
code.append("import java.lang.reflect.*").append(JAVA_LINE_BREAK);
code.append("import com.baidu.bjf.remoting.protobuf.*").append(JAVA_LINE_BREAK);
code.append("import java.util.*").append(JAVA_LINE_BREAK);
if (!StringUtils.isEmpty(getPackage())) {
code.append("import ").append(ClassHelper.getInternalName(cls.getCanonicalName())).append(JAVA_LINE_BREAK);
}
} | [
"private",
"void",
"genImportCode",
"(",
"StringBuilder",
"code",
")",
"{",
"code",
".",
"append",
"(",
"\"import com.google.protobuf.*\"",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"code",
".",
"append",
"(",
"\"import java.io.IOException\"",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"code",
".",
"append",
"(",
"\"import com.baidu.bjf.remoting.protobuf.utils.*\"",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"code",
".",
"append",
"(",
"\"import com.baidu.bjf.remoting.protobuf.code.*\"",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"code",
".",
"append",
"(",
"\"import java.lang.reflect.*\"",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"code",
".",
"append",
"(",
"\"import com.baidu.bjf.remoting.protobuf.*\"",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"code",
".",
"append",
"(",
"\"import java.util.*\"",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"if",
"(",
"!",
"StringUtils",
".",
"isEmpty",
"(",
"getPackage",
"(",
")",
")",
")",
"{",
"code",
".",
"append",
"(",
"\"import \"",
")",
".",
"append",
"(",
"ClassHelper",
".",
"getInternalName",
"(",
"cls",
".",
"getCanonicalName",
"(",
")",
")",
")",
".",
"append",
"(",
"JAVA_LINE_BREAK",
")",
";",
"}",
"}"
] | generate import code
@param code | [
"generate",
"import",
"code"
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java#L260-L272 |
29,242 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeTemplate.java | CodeTemplate.descriptorMethodSource | public static String descriptorMethodSource(Class cls) {
String descriptorClsName = ClassHelper.getInternalName(Descriptor.class.getCanonicalName());
String code = "if (this.descriptor != null) {" + ClassCode.LINE_BREAK +
"return this.descriptor;" + ClassCode.LINE_BREAK +
"}" + ClassCode.LINE_BREAK +
"%s descriptor = CodedConstant.getDescriptor(%s);" + ClassCode.LINE_BREAK +
"return (this.descriptor = descriptor);";
return String.format(code, descriptorClsName,
ClassHelper.getInternalName(cls.getCanonicalName()) + CodeGenerator.JAVA_CLASS_FILE_SUFFIX);
} | java | public static String descriptorMethodSource(Class cls) {
String descriptorClsName = ClassHelper.getInternalName(Descriptor.class.getCanonicalName());
String code = "if (this.descriptor != null) {" + ClassCode.LINE_BREAK +
"return this.descriptor;" + ClassCode.LINE_BREAK +
"}" + ClassCode.LINE_BREAK +
"%s descriptor = CodedConstant.getDescriptor(%s);" + ClassCode.LINE_BREAK +
"return (this.descriptor = descriptor);";
return String.format(code, descriptorClsName,
ClassHelper.getInternalName(cls.getCanonicalName()) + CodeGenerator.JAVA_CLASS_FILE_SUFFIX);
} | [
"public",
"static",
"String",
"descriptorMethodSource",
"(",
"Class",
"cls",
")",
"{",
"String",
"descriptorClsName",
"=",
"ClassHelper",
".",
"getInternalName",
"(",
"Descriptor",
".",
"class",
".",
"getCanonicalName",
"(",
")",
")",
";",
"String",
"code",
"=",
"\"if (this.descriptor != null) {\"",
"+",
"ClassCode",
".",
"LINE_BREAK",
"+",
"\"return this.descriptor;\"",
"+",
"ClassCode",
".",
"LINE_BREAK",
"+",
"\"}\"",
"+",
"ClassCode",
".",
"LINE_BREAK",
"+",
"\"%s descriptor = CodedConstant.getDescriptor(%s);\"",
"+",
"ClassCode",
".",
"LINE_BREAK",
"+",
"\"return (this.descriptor = descriptor);\"",
";",
"return",
"String",
".",
"format",
"(",
"code",
",",
"descriptorClsName",
",",
"ClassHelper",
".",
"getInternalName",
"(",
"cls",
".",
"getCanonicalName",
"(",
")",
")",
"+",
"CodeGenerator",
".",
"JAVA_CLASS_FILE_SUFFIX",
")",
";",
"}"
] | Get getDescriptor method source by template.
@param cls the cls
@return the source code for getDescriptor method | [
"Get",
"getDescriptor",
"method",
"source",
"by",
"template",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeTemplate.java#L36-L48 |
29,243 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java | ProtobufIDLProxy.createEnumClasses | private static List<Class<?>> createEnumClasses(Map<String, EnumElement> enumTypes,
Map<String, String> packageMapping, boolean generateSouceOnly, File sourceOutputDir,
Set<String> compiledClass, Map<String, String> mappedUniName, boolean isUniName) {
List<Class<?>> ret = new ArrayList<Class<?>>();
Set<String> enumNames = new HashSet<String>();
Collection<EnumElement> enums = enumTypes.values();
for (EnumElement enumType : enums) {
String name = enumType.name();
if (enumNames.contains(name)) {
continue;
}
enumNames.add(name);
String packageName = packageMapping.get(name);
Class cls = checkClass(packageName, enumType, mappedUniName, isUniName);
if (cls != null) {
ret.add(cls);
continue;
}
CodeDependent codeDependent = createCodeByType(enumType, true, packageName, mappedUniName, isUniName);
compiledClass.add(codeDependent.name);
compiledClass.add(packageName + PACKAGE_SPLIT_CHAR + codeDependent.name);
if (!generateSouceOnly) {
Class<?> newClass = JDKCompilerHelper.getJdkCompiler().compile(codeDependent.getClassName(),
codeDependent.code, ProtobufIDLProxy.class.getClassLoader(), null, -1);
ret.add(newClass);
} else {
// need to output source code to target path
writeSourceCode(codeDependent, sourceOutputDir);
}
}
return ret;
} | java | private static List<Class<?>> createEnumClasses(Map<String, EnumElement> enumTypes,
Map<String, String> packageMapping, boolean generateSouceOnly, File sourceOutputDir,
Set<String> compiledClass, Map<String, String> mappedUniName, boolean isUniName) {
List<Class<?>> ret = new ArrayList<Class<?>>();
Set<String> enumNames = new HashSet<String>();
Collection<EnumElement> enums = enumTypes.values();
for (EnumElement enumType : enums) {
String name = enumType.name();
if (enumNames.contains(name)) {
continue;
}
enumNames.add(name);
String packageName = packageMapping.get(name);
Class cls = checkClass(packageName, enumType, mappedUniName, isUniName);
if (cls != null) {
ret.add(cls);
continue;
}
CodeDependent codeDependent = createCodeByType(enumType, true, packageName, mappedUniName, isUniName);
compiledClass.add(codeDependent.name);
compiledClass.add(packageName + PACKAGE_SPLIT_CHAR + codeDependent.name);
if (!generateSouceOnly) {
Class<?> newClass = JDKCompilerHelper.getJdkCompiler().compile(codeDependent.getClassName(),
codeDependent.code, ProtobufIDLProxy.class.getClassLoader(), null, -1);
ret.add(newClass);
} else {
// need to output source code to target path
writeSourceCode(codeDependent, sourceOutputDir);
}
}
return ret;
} | [
"private",
"static",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"createEnumClasses",
"(",
"Map",
"<",
"String",
",",
"EnumElement",
">",
"enumTypes",
",",
"Map",
"<",
"String",
",",
"String",
">",
"packageMapping",
",",
"boolean",
"generateSouceOnly",
",",
"File",
"sourceOutputDir",
",",
"Set",
"<",
"String",
">",
"compiledClass",
",",
"Map",
"<",
"String",
",",
"String",
">",
"mappedUniName",
",",
"boolean",
"isUniName",
")",
"{",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"ret",
"=",
"new",
"ArrayList",
"<",
"Class",
"<",
"?",
">",
">",
"(",
")",
";",
"Set",
"<",
"String",
">",
"enumNames",
"=",
"new",
"HashSet",
"<",
"String",
">",
"(",
")",
";",
"Collection",
"<",
"EnumElement",
">",
"enums",
"=",
"enumTypes",
".",
"values",
"(",
")",
";",
"for",
"(",
"EnumElement",
"enumType",
":",
"enums",
")",
"{",
"String",
"name",
"=",
"enumType",
".",
"name",
"(",
")",
";",
"if",
"(",
"enumNames",
".",
"contains",
"(",
"name",
")",
")",
"{",
"continue",
";",
"}",
"enumNames",
".",
"add",
"(",
"name",
")",
";",
"String",
"packageName",
"=",
"packageMapping",
".",
"get",
"(",
"name",
")",
";",
"Class",
"cls",
"=",
"checkClass",
"(",
"packageName",
",",
"enumType",
",",
"mappedUniName",
",",
"isUniName",
")",
";",
"if",
"(",
"cls",
"!=",
"null",
")",
"{",
"ret",
".",
"add",
"(",
"cls",
")",
";",
"continue",
";",
"}",
"CodeDependent",
"codeDependent",
"=",
"createCodeByType",
"(",
"enumType",
",",
"true",
",",
"packageName",
",",
"mappedUniName",
",",
"isUniName",
")",
";",
"compiledClass",
".",
"add",
"(",
"codeDependent",
".",
"name",
")",
";",
"compiledClass",
".",
"add",
"(",
"packageName",
"+",
"PACKAGE_SPLIT_CHAR",
"+",
"codeDependent",
".",
"name",
")",
";",
"if",
"(",
"!",
"generateSouceOnly",
")",
"{",
"Class",
"<",
"?",
">",
"newClass",
"=",
"JDKCompilerHelper",
".",
"getJdkCompiler",
"(",
")",
".",
"compile",
"(",
"codeDependent",
".",
"getClassName",
"(",
")",
",",
"codeDependent",
".",
"code",
",",
"ProtobufIDLProxy",
".",
"class",
".",
"getClassLoader",
"(",
")",
",",
"null",
",",
"-",
"1",
")",
";",
"ret",
".",
"add",
"(",
"newClass",
")",
";",
"}",
"else",
"{",
"// need to output source code to target path\r",
"writeSourceCode",
"(",
"codeDependent",
",",
"sourceOutputDir",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] | Creates the enum classes.
@param enumTypes the enum types
@param packageMapping the package mapping
@param generateSouceOnly the generate souce only
@param sourceOutputDir the source output dir
@param compiledClass the compiled class
@param mappedUniName the mapped uni name
@param isUniName the is uni name
@return the list | [
"Creates",
"the",
"enum",
"classes",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java#L848-L881 |
29,244 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java | ProtobufIDLProxy.getTypeName | private static String getTypeName(FieldElement field) {
DataType type = field.type();
return type.toString();
} | java | private static String getTypeName(FieldElement field) {
DataType type = field.type();
return type.toString();
} | [
"private",
"static",
"String",
"getTypeName",
"(",
"FieldElement",
"field",
")",
"{",
"DataType",
"type",
"=",
"field",
".",
"type",
"(",
")",
";",
"return",
"type",
".",
"toString",
"(",
")",
";",
"}"
] | Gets the type name.
@param field the field
@return the type name | [
"Gets",
"the",
"type",
"name",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/ProtobufIDLProxy.java#L1581-L1584 |
29,245 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapFieldLite.java | MapFieldLite.emptyMapField | @SuppressWarnings({ "unchecked", "cast" })
public static <K, V> MapFieldLite<K, V> emptyMapField() {
return (MapFieldLite<K, V>) EMPTY_MAP_FIELD;
} | java | @SuppressWarnings({ "unchecked", "cast" })
public static <K, V> MapFieldLite<K, V> emptyMapField() {
return (MapFieldLite<K, V>) EMPTY_MAP_FIELD;
} | [
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
",",
"\"cast\"",
"}",
")",
"public",
"static",
"<",
"K",
",",
"V",
">",
"MapFieldLite",
"<",
"K",
",",
"V",
">",
"emptyMapField",
"(",
")",
"{",
"return",
"(",
"MapFieldLite",
"<",
"K",
",",
"V",
">",
")",
"EMPTY_MAP_FIELD",
";",
"}"
] | Returns an singleton immutable empty MapFieldLite instance.
@param <K> the key type
@param <V> the value type
@return the map field lite | [
"Returns",
"an",
"singleton",
"immutable",
"empty",
"MapFieldLite",
"instance",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapFieldLite.java#L72-L75 |
29,246 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapFieldLite.java | MapFieldLite.mergeFrom | public void mergeFrom(MapFieldLite<K, V> other) {
ensureMutable();
if (!other.isEmpty()) {
putAll(other);
}
} | java | public void mergeFrom(MapFieldLite<K, V> other) {
ensureMutable();
if (!other.isEmpty()) {
putAll(other);
}
} | [
"public",
"void",
"mergeFrom",
"(",
"MapFieldLite",
"<",
"K",
",",
"V",
">",
"other",
")",
"{",
"ensureMutable",
"(",
")",
";",
"if",
"(",
"!",
"other",
".",
"isEmpty",
"(",
")",
")",
"{",
"putAll",
"(",
"other",
")",
";",
"}",
"}"
] | Merge from.
@param other the other | [
"Merge",
"from",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/MapFieldLite.java#L82-L87 |
29,247 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java | CodeGenerator.genImportCode | private void genImportCode(ClassCode code) {
code.importClass("java.util.*");
code.importClass("java.io.IOException");
code.importClass("java.lang.reflect.*");
code.importClass("com.baidu.bjf.remoting.protobuf.code.*");
code.importClass("com.baidu.bjf.remoting.protobuf.utils.*");
code.importClass("com.baidu.bjf.remoting.protobuf.*");
code.importClass("com.google.protobuf.*");
if (!StringUtils.isEmpty(getPackage())) {
code.importClass(ClassHelper.getInternalName(cls.getCanonicalName()));
}
} | java | private void genImportCode(ClassCode code) {
code.importClass("java.util.*");
code.importClass("java.io.IOException");
code.importClass("java.lang.reflect.*");
code.importClass("com.baidu.bjf.remoting.protobuf.code.*");
code.importClass("com.baidu.bjf.remoting.protobuf.utils.*");
code.importClass("com.baidu.bjf.remoting.protobuf.*");
code.importClass("com.google.protobuf.*");
if (!StringUtils.isEmpty(getPackage())) {
code.importClass(ClassHelper.getInternalName(cls.getCanonicalName()));
}
} | [
"private",
"void",
"genImportCode",
"(",
"ClassCode",
"code",
")",
"{",
"code",
".",
"importClass",
"(",
"\"java.util.*\"",
")",
";",
"code",
".",
"importClass",
"(",
"\"java.io.IOException\"",
")",
";",
"code",
".",
"importClass",
"(",
"\"java.lang.reflect.*\"",
")",
";",
"code",
".",
"importClass",
"(",
"\"com.baidu.bjf.remoting.protobuf.code.*\"",
")",
";",
"code",
".",
"importClass",
"(",
"\"com.baidu.bjf.remoting.protobuf.utils.*\"",
")",
";",
"code",
".",
"importClass",
"(",
"\"com.baidu.bjf.remoting.protobuf.*\"",
")",
";",
"code",
".",
"importClass",
"(",
"\"com.google.protobuf.*\"",
")",
";",
"if",
"(",
"!",
"StringUtils",
".",
"isEmpty",
"(",
"getPackage",
"(",
")",
")",
")",
"{",
"code",
".",
"importClass",
"(",
"ClassHelper",
".",
"getInternalName",
"(",
"cls",
".",
"getCanonicalName",
"(",
")",
")",
")",
";",
"}",
"}"
] | generate import code.
@param code the code | [
"generate",
"import",
"code",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java#L169-L181 |
29,248 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java | CodeGenerator.getDecodeMethodCode | private MethodCode getDecodeMethodCode() {
MethodCode mc = new MethodCode();
mc.setName("decode");
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.setReturnType(ClassHelper.getInternalName(cls.getCanonicalName()));
mc.addParameter("byte[]", "bb");
mc.addException("IOException");
// add method code
mc.appendLineCode1("CodedInputStream input = CodedInputStream.newInstance(bb, 0, bb.length)");
getParseBytesMethodCode(mc);
return mc;
} | java | private MethodCode getDecodeMethodCode() {
MethodCode mc = new MethodCode();
mc.setName("decode");
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.setReturnType(ClassHelper.getInternalName(cls.getCanonicalName()));
mc.addParameter("byte[]", "bb");
mc.addException("IOException");
// add method code
mc.appendLineCode1("CodedInputStream input = CodedInputStream.newInstance(bb, 0, bb.length)");
getParseBytesMethodCode(mc);
return mc;
} | [
"private",
"MethodCode",
"getDecodeMethodCode",
"(",
")",
"{",
"MethodCode",
"mc",
"=",
"new",
"MethodCode",
"(",
")",
";",
"mc",
".",
"setName",
"(",
"\"decode\"",
")",
";",
"mc",
".",
"setScope",
"(",
"ClassCode",
".",
"SCOPE_PUBLIC",
")",
";",
"mc",
".",
"setReturnType",
"(",
"ClassHelper",
".",
"getInternalName",
"(",
"cls",
".",
"getCanonicalName",
"(",
")",
")",
")",
";",
"mc",
".",
"addParameter",
"(",
"\"byte[]\"",
",",
"\"bb\"",
")",
";",
"mc",
".",
"addException",
"(",
"\"IOException\"",
")",
";",
"// add method code",
"mc",
".",
"appendLineCode1",
"(",
"\"CodedInputStream input = CodedInputStream.newInstance(bb, 0, bb.length)\"",
")",
";",
"getParseBytesMethodCode",
"(",
"mc",
")",
";",
"return",
"mc",
";",
"}"
] | Gets the decode method code.
@return the decode method code | [
"Gets",
"the",
"decode",
"method",
"code",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java#L355-L369 |
29,249 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java | CodeGenerator.getGetDescriptorMethodCode | private MethodCode getGetDescriptorMethodCode() {
String descriptorClsName = ClassHelper.getInternalName(Descriptor.class.getCanonicalName());
MethodCode mc = new MethodCode();
mc.setName("getDescriptor");
mc.setReturnType(descriptorClsName);
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.addException("IOException");
String methodSource = CodeTemplate.descriptorMethodSource(cls);
mc.appendLineCode0(methodSource);
return mc;
} | java | private MethodCode getGetDescriptorMethodCode() {
String descriptorClsName = ClassHelper.getInternalName(Descriptor.class.getCanonicalName());
MethodCode mc = new MethodCode();
mc.setName("getDescriptor");
mc.setReturnType(descriptorClsName);
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.addException("IOException");
String methodSource = CodeTemplate.descriptorMethodSource(cls);
mc.appendLineCode0(methodSource);
return mc;
} | [
"private",
"MethodCode",
"getGetDescriptorMethodCode",
"(",
")",
"{",
"String",
"descriptorClsName",
"=",
"ClassHelper",
".",
"getInternalName",
"(",
"Descriptor",
".",
"class",
".",
"getCanonicalName",
"(",
")",
")",
";",
"MethodCode",
"mc",
"=",
"new",
"MethodCode",
"(",
")",
";",
"mc",
".",
"setName",
"(",
"\"getDescriptor\"",
")",
";",
"mc",
".",
"setReturnType",
"(",
"descriptorClsName",
")",
";",
"mc",
".",
"setScope",
"(",
"ClassCode",
".",
"SCOPE_PUBLIC",
")",
";",
"mc",
".",
"addException",
"(",
"\"IOException\"",
")",
";",
"String",
"methodSource",
"=",
"CodeTemplate",
".",
"descriptorMethodSource",
"(",
"cls",
")",
";",
"mc",
".",
"appendLineCode0",
"(",
"methodSource",
")",
";",
"return",
"mc",
";",
"}"
] | Gets the gets the descriptor method code.
@return the gets the descriptor method code | [
"Gets",
"the",
"gets",
"the",
"descriptor",
"method",
"code",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java#L376-L389 |
29,250 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java | CodeGenerator.getWriteToMethodCode | private MethodCode getWriteToMethodCode() {
MethodCode mc = new MethodCode();
mc.setName("writeTo");
mc.setReturnType("void");
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.addParameter(ClassHelper.getInternalName(cls.getCanonicalName()), "t");
mc.addParameter("CodedOutputStream", "output");
mc.addException("IOException");
Set<Integer> orders = new HashSet<Integer>();
for (FieldInfo field : fields) {
boolean isList = field.isList();
// check type
if (!isList) {
checkType(field.getFieldType(), field.getField());
}
if (orders.contains(field.getOrder())) {
throw new IllegalArgumentException("Field order '" + field.getOrder() + "' on field"
+ field.getField().getName() + " already exsit.");
}
// define field
mc.appendLineCode0(CodedConstant.getMappedTypeDefined(field.getOrder(), field.getFieldType(),
getAccessByField("t", field.getField(), cls), isList));
if (field.isRequired()) {
mc.appendLineCode0(CodedConstant.getRequiredCheck(field.getOrder(), field.getField()));
}
}
for (FieldInfo field : fields) {
boolean isList = field.isList();
// set write to byte
mc.appendLineCode0(
CodedConstant.getMappedWriteCode(field, "output", field.getOrder(), field.getFieldType(), isList));
}
mc.appendLineCode1("output.flush()");
return mc;
} | java | private MethodCode getWriteToMethodCode() {
MethodCode mc = new MethodCode();
mc.setName("writeTo");
mc.setReturnType("void");
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.addParameter(ClassHelper.getInternalName(cls.getCanonicalName()), "t");
mc.addParameter("CodedOutputStream", "output");
mc.addException("IOException");
Set<Integer> orders = new HashSet<Integer>();
for (FieldInfo field : fields) {
boolean isList = field.isList();
// check type
if (!isList) {
checkType(field.getFieldType(), field.getField());
}
if (orders.contains(field.getOrder())) {
throw new IllegalArgumentException("Field order '" + field.getOrder() + "' on field"
+ field.getField().getName() + " already exsit.");
}
// define field
mc.appendLineCode0(CodedConstant.getMappedTypeDefined(field.getOrder(), field.getFieldType(),
getAccessByField("t", field.getField(), cls), isList));
if (field.isRequired()) {
mc.appendLineCode0(CodedConstant.getRequiredCheck(field.getOrder(), field.getField()));
}
}
for (FieldInfo field : fields) {
boolean isList = field.isList();
// set write to byte
mc.appendLineCode0(
CodedConstant.getMappedWriteCode(field, "output", field.getOrder(), field.getFieldType(), isList));
}
mc.appendLineCode1("output.flush()");
return mc;
} | [
"private",
"MethodCode",
"getWriteToMethodCode",
"(",
")",
"{",
"MethodCode",
"mc",
"=",
"new",
"MethodCode",
"(",
")",
";",
"mc",
".",
"setName",
"(",
"\"writeTo\"",
")",
";",
"mc",
".",
"setReturnType",
"(",
"\"void\"",
")",
";",
"mc",
".",
"setScope",
"(",
"ClassCode",
".",
"SCOPE_PUBLIC",
")",
";",
"mc",
".",
"addParameter",
"(",
"ClassHelper",
".",
"getInternalName",
"(",
"cls",
".",
"getCanonicalName",
"(",
")",
")",
",",
"\"t\"",
")",
";",
"mc",
".",
"addParameter",
"(",
"\"CodedOutputStream\"",
",",
"\"output\"",
")",
";",
"mc",
".",
"addException",
"(",
"\"IOException\"",
")",
";",
"Set",
"<",
"Integer",
">",
"orders",
"=",
"new",
"HashSet",
"<",
"Integer",
">",
"(",
")",
";",
"for",
"(",
"FieldInfo",
"field",
":",
"fields",
")",
"{",
"boolean",
"isList",
"=",
"field",
".",
"isList",
"(",
")",
";",
"// check type",
"if",
"(",
"!",
"isList",
")",
"{",
"checkType",
"(",
"field",
".",
"getFieldType",
"(",
")",
",",
"field",
".",
"getField",
"(",
")",
")",
";",
"}",
"if",
"(",
"orders",
".",
"contains",
"(",
"field",
".",
"getOrder",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Field order '\"",
"+",
"field",
".",
"getOrder",
"(",
")",
"+",
"\"' on field\"",
"+",
"field",
".",
"getField",
"(",
")",
".",
"getName",
"(",
")",
"+",
"\" already exsit.\"",
")",
";",
"}",
"// define field",
"mc",
".",
"appendLineCode0",
"(",
"CodedConstant",
".",
"getMappedTypeDefined",
"(",
"field",
".",
"getOrder",
"(",
")",
",",
"field",
".",
"getFieldType",
"(",
")",
",",
"getAccessByField",
"(",
"\"t\"",
",",
"field",
".",
"getField",
"(",
")",
",",
"cls",
")",
",",
"isList",
")",
")",
";",
"if",
"(",
"field",
".",
"isRequired",
"(",
")",
")",
"{",
"mc",
".",
"appendLineCode0",
"(",
"CodedConstant",
".",
"getRequiredCheck",
"(",
"field",
".",
"getOrder",
"(",
")",
",",
"field",
".",
"getField",
"(",
")",
")",
")",
";",
"}",
"}",
"for",
"(",
"FieldInfo",
"field",
":",
"fields",
")",
"{",
"boolean",
"isList",
"=",
"field",
".",
"isList",
"(",
")",
";",
"// set write to byte",
"mc",
".",
"appendLineCode0",
"(",
"CodedConstant",
".",
"getMappedWriteCode",
"(",
"field",
",",
"\"output\"",
",",
"field",
".",
"getOrder",
"(",
")",
",",
"field",
".",
"getFieldType",
"(",
")",
",",
"isList",
")",
")",
";",
"}",
"mc",
".",
"appendLineCode1",
"(",
"\"output.flush()\"",
")",
";",
"return",
"mc",
";",
"}"
] | Gets the write to method code.
@return the write to method code | [
"Gets",
"the",
"write",
"to",
"method",
"code",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java#L476-L517 |
29,251 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java | CodeGenerator.getSizeMethodCode | private MethodCode getSizeMethodCode() {
MethodCode mc = new MethodCode();
mc.setName("size");
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.setReturnType("int");
mc.addParameter(ClassHelper.getInternalName(cls.getCanonicalName()), "t");
mc.addException("IOException");
// add method code
mc.appendLineCode1("int size = 0");
Set<Integer> orders = new HashSet<Integer>();
// encode method
for (FieldInfo field : fields) {
boolean isList = field.isList();
// check type
if (!isList) {
checkType(field.getFieldType(), field.getField());
}
if (orders.contains(field.getOrder())) {
throw new IllegalArgumentException("Field order '" + field.getOrder() + "' on field"
+ field.getField().getName() + " already exsit.");
}
// define field
mc.appendLineCode0(CodedConstant.getMappedTypeDefined(field.getOrder(), field.getFieldType(),
getAccessByField("t", field.getField(), cls), isList));
// compute size
StringBuilder code = new StringBuilder();
code.append("if (!CodedConstant.isNull(").append(getAccessByField("t", field.getField(), cls)).append("))")
.append("{");
mc.appendLineCode0(code.toString());
code.setLength(0);
code.append("size += ");
code.append(CodedConstant.getMappedTypeSize(field, field.getOrder(), field.getFieldType(), isList, debug,
outputPath));
code.append("}");
mc.appendLineCode0(code.toString());
if (field.isRequired()) {
mc.appendLineCode0(CodedConstant.getRequiredCheck(field.getOrder(), field.getField()));
}
}
mc.appendLineCode1("return size");
return mc;
} | java | private MethodCode getSizeMethodCode() {
MethodCode mc = new MethodCode();
mc.setName("size");
mc.setScope(ClassCode.SCOPE_PUBLIC);
mc.setReturnType("int");
mc.addParameter(ClassHelper.getInternalName(cls.getCanonicalName()), "t");
mc.addException("IOException");
// add method code
mc.appendLineCode1("int size = 0");
Set<Integer> orders = new HashSet<Integer>();
// encode method
for (FieldInfo field : fields) {
boolean isList = field.isList();
// check type
if (!isList) {
checkType(field.getFieldType(), field.getField());
}
if (orders.contains(field.getOrder())) {
throw new IllegalArgumentException("Field order '" + field.getOrder() + "' on field"
+ field.getField().getName() + " already exsit.");
}
// define field
mc.appendLineCode0(CodedConstant.getMappedTypeDefined(field.getOrder(), field.getFieldType(),
getAccessByField("t", field.getField(), cls), isList));
// compute size
StringBuilder code = new StringBuilder();
code.append("if (!CodedConstant.isNull(").append(getAccessByField("t", field.getField(), cls)).append("))")
.append("{");
mc.appendLineCode0(code.toString());
code.setLength(0);
code.append("size += ");
code.append(CodedConstant.getMappedTypeSize(field, field.getOrder(), field.getFieldType(), isList, debug,
outputPath));
code.append("}");
mc.appendLineCode0(code.toString());
if (field.isRequired()) {
mc.appendLineCode0(CodedConstant.getRequiredCheck(field.getOrder(), field.getField()));
}
}
mc.appendLineCode1("return size");
return mc;
} | [
"private",
"MethodCode",
"getSizeMethodCode",
"(",
")",
"{",
"MethodCode",
"mc",
"=",
"new",
"MethodCode",
"(",
")",
";",
"mc",
".",
"setName",
"(",
"\"size\"",
")",
";",
"mc",
".",
"setScope",
"(",
"ClassCode",
".",
"SCOPE_PUBLIC",
")",
";",
"mc",
".",
"setReturnType",
"(",
"\"int\"",
")",
";",
"mc",
".",
"addParameter",
"(",
"ClassHelper",
".",
"getInternalName",
"(",
"cls",
".",
"getCanonicalName",
"(",
")",
")",
",",
"\"t\"",
")",
";",
"mc",
".",
"addException",
"(",
"\"IOException\"",
")",
";",
"// add method code",
"mc",
".",
"appendLineCode1",
"(",
"\"int size = 0\"",
")",
";",
"Set",
"<",
"Integer",
">",
"orders",
"=",
"new",
"HashSet",
"<",
"Integer",
">",
"(",
")",
";",
"// encode method",
"for",
"(",
"FieldInfo",
"field",
":",
"fields",
")",
"{",
"boolean",
"isList",
"=",
"field",
".",
"isList",
"(",
")",
";",
"// check type",
"if",
"(",
"!",
"isList",
")",
"{",
"checkType",
"(",
"field",
".",
"getFieldType",
"(",
")",
",",
"field",
".",
"getField",
"(",
")",
")",
";",
"}",
"if",
"(",
"orders",
".",
"contains",
"(",
"field",
".",
"getOrder",
"(",
")",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Field order '\"",
"+",
"field",
".",
"getOrder",
"(",
")",
"+",
"\"' on field\"",
"+",
"field",
".",
"getField",
"(",
")",
".",
"getName",
"(",
")",
"+",
"\" already exsit.\"",
")",
";",
"}",
"// define field",
"mc",
".",
"appendLineCode0",
"(",
"CodedConstant",
".",
"getMappedTypeDefined",
"(",
"field",
".",
"getOrder",
"(",
")",
",",
"field",
".",
"getFieldType",
"(",
")",
",",
"getAccessByField",
"(",
"\"t\"",
",",
"field",
".",
"getField",
"(",
")",
",",
"cls",
")",
",",
"isList",
")",
")",
";",
"// compute size",
"StringBuilder",
"code",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"code",
".",
"append",
"(",
"\"if (!CodedConstant.isNull(\"",
")",
".",
"append",
"(",
"getAccessByField",
"(",
"\"t\"",
",",
"field",
".",
"getField",
"(",
")",
",",
"cls",
")",
")",
".",
"append",
"(",
"\"))\"",
")",
".",
"append",
"(",
"\"{\"",
")",
";",
"mc",
".",
"appendLineCode0",
"(",
"code",
".",
"toString",
"(",
")",
")",
";",
"code",
".",
"setLength",
"(",
"0",
")",
";",
"code",
".",
"append",
"(",
"\"size += \"",
")",
";",
"code",
".",
"append",
"(",
"CodedConstant",
".",
"getMappedTypeSize",
"(",
"field",
",",
"field",
".",
"getOrder",
"(",
")",
",",
"field",
".",
"getFieldType",
"(",
")",
",",
"isList",
",",
"debug",
",",
"outputPath",
")",
")",
";",
"code",
".",
"append",
"(",
"\"}\"",
")",
";",
"mc",
".",
"appendLineCode0",
"(",
"code",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"field",
".",
"isRequired",
"(",
")",
")",
"{",
"mc",
".",
"appendLineCode0",
"(",
"CodedConstant",
".",
"getRequiredCheck",
"(",
"field",
".",
"getOrder",
"(",
")",
",",
"field",
".",
"getField",
"(",
")",
")",
")",
";",
"}",
"}",
"mc",
".",
"appendLineCode1",
"(",
"\"return size\"",
")",
";",
"return",
"mc",
";",
"}"
] | Gets the size method code.
@return the size method code | [
"Gets",
"the",
"size",
"method",
"code",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java#L524-L574 |
29,252 | jhunters/jprotobuf | src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java | CodeGenerator.getAccessByField | protected String getAccessByField(String target, Field field, Class<?> cls) {
if (field.getModifiers() == Modifier.PUBLIC) {
return target + ClassHelper.PACKAGE_SEPARATOR + field.getName();
}
// check if has getter method
String getter;
if ("boolean".equalsIgnoreCase(field.getType().getCanonicalName())) {
getter = "is" + CodedConstant.capitalize(field.getName());
} else {
getter = "get" + CodedConstant.capitalize(field.getName());
}
// check method exist
try {
cls.getMethod(getter, new Class<?>[0]);
return target + ClassHelper.PACKAGE_SEPARATOR + getter + "()";
} catch (Exception e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(e.getMessage(), e);
}
}
String type = field.getType().getCanonicalName();
if ("[B".equals(type) || "[Ljava.lang.Byte;".equals(type) || "java.lang.Byte[]".equals(type)) {
type = "byte[]";
}
// use reflection to get value
String code = "(" + FieldUtils.toObjectType(type) + ") ";
code += "FieldUtils.getField(" + target + ", \"" + field.getName() + "\")";
return code;
} | java | protected String getAccessByField(String target, Field field, Class<?> cls) {
if (field.getModifiers() == Modifier.PUBLIC) {
return target + ClassHelper.PACKAGE_SEPARATOR + field.getName();
}
// check if has getter method
String getter;
if ("boolean".equalsIgnoreCase(field.getType().getCanonicalName())) {
getter = "is" + CodedConstant.capitalize(field.getName());
} else {
getter = "get" + CodedConstant.capitalize(field.getName());
}
// check method exist
try {
cls.getMethod(getter, new Class<?>[0]);
return target + ClassHelper.PACKAGE_SEPARATOR + getter + "()";
} catch (Exception e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(e.getMessage(), e);
}
}
String type = field.getType().getCanonicalName();
if ("[B".equals(type) || "[Ljava.lang.Byte;".equals(type) || "java.lang.Byte[]".equals(type)) {
type = "byte[]";
}
// use reflection to get value
String code = "(" + FieldUtils.toObjectType(type) + ") ";
code += "FieldUtils.getField(" + target + ", \"" + field.getName() + "\")";
return code;
} | [
"protected",
"String",
"getAccessByField",
"(",
"String",
"target",
",",
"Field",
"field",
",",
"Class",
"<",
"?",
">",
"cls",
")",
"{",
"if",
"(",
"field",
".",
"getModifiers",
"(",
")",
"==",
"Modifier",
".",
"PUBLIC",
")",
"{",
"return",
"target",
"+",
"ClassHelper",
".",
"PACKAGE_SEPARATOR",
"+",
"field",
".",
"getName",
"(",
")",
";",
"}",
"// check if has getter method",
"String",
"getter",
";",
"if",
"(",
"\"boolean\"",
".",
"equalsIgnoreCase",
"(",
"field",
".",
"getType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
")",
"{",
"getter",
"=",
"\"is\"",
"+",
"CodedConstant",
".",
"capitalize",
"(",
"field",
".",
"getName",
"(",
")",
")",
";",
"}",
"else",
"{",
"getter",
"=",
"\"get\"",
"+",
"CodedConstant",
".",
"capitalize",
"(",
"field",
".",
"getName",
"(",
")",
")",
";",
"}",
"// check method exist",
"try",
"{",
"cls",
".",
"getMethod",
"(",
"getter",
",",
"new",
"Class",
"<",
"?",
">",
"[",
"0",
"]",
")",
";",
"return",
"target",
"+",
"ClassHelper",
".",
"PACKAGE_SEPARATOR",
"+",
"getter",
"+",
"\"()\"",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"if",
"(",
"LOGGER",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
")",
";",
"}",
"}",
"String",
"type",
"=",
"field",
".",
"getType",
"(",
")",
".",
"getCanonicalName",
"(",
")",
";",
"if",
"(",
"\"[B\"",
".",
"equals",
"(",
"type",
")",
"||",
"\"[Ljava.lang.Byte;\"",
".",
"equals",
"(",
"type",
")",
"||",
"\"java.lang.Byte[]\"",
".",
"equals",
"(",
"type",
")",
")",
"{",
"type",
"=",
"\"byte[]\"",
";",
"}",
"// use reflection to get value",
"String",
"code",
"=",
"\"(\"",
"+",
"FieldUtils",
".",
"toObjectType",
"(",
"type",
")",
"+",
"\") \"",
";",
"code",
"+=",
"\"FieldUtils.getField(\"",
"+",
"target",
"+",
"\", \\\"\"",
"+",
"field",
".",
"getName",
"(",
")",
"+",
"\"\\\")\"",
";",
"return",
"code",
";",
"}"
] | get field access code.
@param target target instance name
@param field java field instance
@param cls mapped class
@return full field access java code | [
"get",
"field",
"access",
"code",
"."
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/src/main/java/com/baidu/bjf/remoting/protobuf/code/CodeGenerator.java#L584-L615 |
29,253 | jhunters/jprotobuf | v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/CodePrinter.java | CodePrinter.printCode | public static void printCode(String code, String desc) {
System.out.println("--------------------------" + desc + " begin--------------------------");
System.out.println(code);
System.out.println("--------------------------" + desc + " end--------------------------");
} | java | public static void printCode(String code, String desc) {
System.out.println("--------------------------" + desc + " begin--------------------------");
System.out.println(code);
System.out.println("--------------------------" + desc + " end--------------------------");
} | [
"public",
"static",
"void",
"printCode",
"(",
"String",
"code",
",",
"String",
"desc",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"--------------------------\"",
"+",
"desc",
"+",
"\" begin--------------------------\"",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"code",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"--------------------------\"",
"+",
"desc",
"+",
"\" end--------------------------\"",
")",
";",
"}"
] | print code to console
@param code code in string
@param desc code description | [
"print",
"code",
"to",
"console"
] | 55832c9b4792afb128e5b35139d8a3891561d8a3 | https://github.com/jhunters/jprotobuf/blob/55832c9b4792afb128e5b35139d8a3891561d8a3/v3/src/main/java/com/baidu/bjf/remoting/protobuf/utils/CodePrinter.java#L33-L37 |
29,254 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/P12Util.java | P12Util.getFirstPrivateKeyEntryFromP12InputStream | public static PrivateKeyEntry getFirstPrivateKeyEntryFromP12InputStream(final InputStream p12InputStream, final String password) throws KeyStoreException, IOException {
Objects.requireNonNull(password, "Password may be blank, but must not be null.");
final KeyStore keyStore = KeyStore.getInstance("PKCS12");
try {
keyStore.load(p12InputStream, password.toCharArray());
} catch (NoSuchAlgorithmException | CertificateException e) {
throw new KeyStoreException(e);
}
final Enumeration<String> aliases = keyStore.aliases();
final KeyStore.PasswordProtection passwordProtection = new KeyStore.PasswordProtection(password.toCharArray());
while (aliases.hasMoreElements()) {
final String alias = aliases.nextElement();
KeyStore.Entry entry;
try {
try {
entry = keyStore.getEntry(alias, passwordProtection);
} catch (final UnsupportedOperationException e) {
entry = keyStore.getEntry(alias, null);
}
} catch (final UnrecoverableEntryException | NoSuchAlgorithmException e) {
throw new KeyStoreException(e);
}
if (entry instanceof KeyStore.PrivateKeyEntry) {
return (PrivateKeyEntry) entry;
}
}
throw new KeyStoreException("Key store did not contain any private key entries.");
} | java | public static PrivateKeyEntry getFirstPrivateKeyEntryFromP12InputStream(final InputStream p12InputStream, final String password) throws KeyStoreException, IOException {
Objects.requireNonNull(password, "Password may be blank, but must not be null.");
final KeyStore keyStore = KeyStore.getInstance("PKCS12");
try {
keyStore.load(p12InputStream, password.toCharArray());
} catch (NoSuchAlgorithmException | CertificateException e) {
throw new KeyStoreException(e);
}
final Enumeration<String> aliases = keyStore.aliases();
final KeyStore.PasswordProtection passwordProtection = new KeyStore.PasswordProtection(password.toCharArray());
while (aliases.hasMoreElements()) {
final String alias = aliases.nextElement();
KeyStore.Entry entry;
try {
try {
entry = keyStore.getEntry(alias, passwordProtection);
} catch (final UnsupportedOperationException e) {
entry = keyStore.getEntry(alias, null);
}
} catch (final UnrecoverableEntryException | NoSuchAlgorithmException e) {
throw new KeyStoreException(e);
}
if (entry instanceof KeyStore.PrivateKeyEntry) {
return (PrivateKeyEntry) entry;
}
}
throw new KeyStoreException("Key store did not contain any private key entries.");
} | [
"public",
"static",
"PrivateKeyEntry",
"getFirstPrivateKeyEntryFromP12InputStream",
"(",
"final",
"InputStream",
"p12InputStream",
",",
"final",
"String",
"password",
")",
"throws",
"KeyStoreException",
",",
"IOException",
"{",
"Objects",
".",
"requireNonNull",
"(",
"password",
",",
"\"Password may be blank, but must not be null.\"",
")",
";",
"final",
"KeyStore",
"keyStore",
"=",
"KeyStore",
".",
"getInstance",
"(",
"\"PKCS12\"",
")",
";",
"try",
"{",
"keyStore",
".",
"load",
"(",
"p12InputStream",
",",
"password",
".",
"toCharArray",
"(",
")",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"|",
"CertificateException",
"e",
")",
"{",
"throw",
"new",
"KeyStoreException",
"(",
"e",
")",
";",
"}",
"final",
"Enumeration",
"<",
"String",
">",
"aliases",
"=",
"keyStore",
".",
"aliases",
"(",
")",
";",
"final",
"KeyStore",
".",
"PasswordProtection",
"passwordProtection",
"=",
"new",
"KeyStore",
".",
"PasswordProtection",
"(",
"password",
".",
"toCharArray",
"(",
")",
")",
";",
"while",
"(",
"aliases",
".",
"hasMoreElements",
"(",
")",
")",
"{",
"final",
"String",
"alias",
"=",
"aliases",
".",
"nextElement",
"(",
")",
";",
"KeyStore",
".",
"Entry",
"entry",
";",
"try",
"{",
"try",
"{",
"entry",
"=",
"keyStore",
".",
"getEntry",
"(",
"alias",
",",
"passwordProtection",
")",
";",
"}",
"catch",
"(",
"final",
"UnsupportedOperationException",
"e",
")",
"{",
"entry",
"=",
"keyStore",
".",
"getEntry",
"(",
"alias",
",",
"null",
")",
";",
"}",
"}",
"catch",
"(",
"final",
"UnrecoverableEntryException",
"|",
"NoSuchAlgorithmException",
"e",
")",
"{",
"throw",
"new",
"KeyStoreException",
"(",
"e",
")",
";",
"}",
"if",
"(",
"entry",
"instanceof",
"KeyStore",
".",
"PrivateKeyEntry",
")",
"{",
"return",
"(",
"PrivateKeyEntry",
")",
"entry",
";",
"}",
"}",
"throw",
"new",
"KeyStoreException",
"(",
"\"Key store did not contain any private key entries.\"",
")",
";",
"}"
] | Returns the first private key entry found in the given keystore. If more than one private key is present, the
key that is returned is undefined.
@param p12InputStream an input stream for a PKCS#12 keystore
@param password the password to be used to load the keystore and its entries; may be blank, but must not be
{@code null}
@return the first private key entry found in the given keystore
@throws KeyStoreException if a private key entry could not be extracted from the given keystore for any reason
@throws IOException if the given input stream could not be read for any reason | [
"Returns",
"the",
"first",
"private",
"key",
"entry",
"found",
"in",
"the",
"given",
"keystore",
".",
"If",
"more",
"than",
"one",
"private",
"key",
"is",
"present",
"the",
"key",
"that",
"is",
"returned",
"is",
"undefined",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/P12Util.java#L56-L91 |
29,255 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/server/BaseHttp2Server.java | BaseHttp2Server.start | public Future<Void> start(final int port) {
final ChannelFuture channelFuture = this.bootstrap.bind(port);
this.allChannels.add(channelFuture.channel());
return channelFuture;
} | java | public Future<Void> start(final int port) {
final ChannelFuture channelFuture = this.bootstrap.bind(port);
this.allChannels.add(channelFuture.channel());
return channelFuture;
} | [
"public",
"Future",
"<",
"Void",
">",
"start",
"(",
"final",
"int",
"port",
")",
"{",
"final",
"ChannelFuture",
"channelFuture",
"=",
"this",
".",
"bootstrap",
".",
"bind",
"(",
"port",
")",
";",
"this",
".",
"allChannels",
".",
"add",
"(",
"channelFuture",
".",
"channel",
"(",
")",
")",
";",
"return",
"channelFuture",
";",
"}"
] | Starts this mock server and listens for traffic on the given port.
@param port the port to which this server should bind
@return a {@code Future} that will succeed when the server has bound to the given port and is ready to accept
traffic | [
"Starts",
"this",
"mock",
"server",
"and",
"listens",
"for",
"traffic",
"on",
"the",
"given",
"port",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/server/BaseHttp2Server.java#L119-L124 |
29,256 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/server/ServerChannelClassUtil.java | ServerChannelClassUtil.getServerSocketChannelClass | @SuppressWarnings("unchecked")
static Class<? extends ServerChannel> getServerSocketChannelClass(final EventLoopGroup eventLoopGroup) {
Objects.requireNonNull(eventLoopGroup);
final String serverSocketChannelClassName = SERVER_SOCKET_CHANNEL_CLASSES.get(eventLoopGroup.getClass().getName());
if (serverSocketChannelClassName == null) {
throw new IllegalArgumentException("No server socket channel class found for event loop group type: " + eventLoopGroup.getClass().getName());
}
try {
return Class.forName(serverSocketChannelClassName).asSubclass(ServerChannel.class);
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} | java | @SuppressWarnings("unchecked")
static Class<? extends ServerChannel> getServerSocketChannelClass(final EventLoopGroup eventLoopGroup) {
Objects.requireNonNull(eventLoopGroup);
final String serverSocketChannelClassName = SERVER_SOCKET_CHANNEL_CLASSES.get(eventLoopGroup.getClass().getName());
if (serverSocketChannelClassName == null) {
throw new IllegalArgumentException("No server socket channel class found for event loop group type: " + eventLoopGroup.getClass().getName());
}
try {
return Class.forName(serverSocketChannelClassName).asSubclass(ServerChannel.class);
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"static",
"Class",
"<",
"?",
"extends",
"ServerChannel",
">",
"getServerSocketChannelClass",
"(",
"final",
"EventLoopGroup",
"eventLoopGroup",
")",
"{",
"Objects",
".",
"requireNonNull",
"(",
"eventLoopGroup",
")",
";",
"final",
"String",
"serverSocketChannelClassName",
"=",
"SERVER_SOCKET_CHANNEL_CLASSES",
".",
"get",
"(",
"eventLoopGroup",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"serverSocketChannelClassName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No server socket channel class found for event loop group type: \"",
"+",
"eventLoopGroup",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"try",
"{",
"return",
"Class",
".",
"forName",
"(",
"serverSocketChannelClassName",
")",
".",
"asSubclass",
"(",
"ServerChannel",
".",
"class",
")",
";",
"}",
"catch",
"(",
"final",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a server socket channel class suitable for specified event loop group.
@param eventLoopGroup the event loop group for which to identify an appropriate socket channel class; must not
be {@code null}
@return a server socket channel class suitable for use with the given event loop group
@throws IllegalArgumentException in case of null or unrecognized event loop group | [
"Returns",
"a",
"server",
"socket",
"channel",
"class",
"suitable",
"for",
"specified",
"event",
"loop",
"group",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/server/ServerChannelClassUtil.java#L53-L68 |
29,257 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/ApnsChannelFactory.java | ApnsChannelFactory.create | @Override
public Future<Channel> create(final Promise<Channel> channelReadyPromise) {
final long delay = this.currentDelaySeconds.get();
channelReadyPromise.addListener(new GenericFutureListener<Future<Channel>>() {
@Override
public void operationComplete(final Future<Channel> future) {
final long updatedDelay = future.isSuccess() ? 0 :
Math.max(Math.min(delay * 2, MAX_CONNECT_DELAY_SECONDS), MIN_CONNECT_DELAY_SECONDS);
ApnsChannelFactory.this.currentDelaySeconds.compareAndSet(delay, updatedDelay);
}
});
this.bootstrapTemplate.config().group().schedule(new Runnable() {
@Override
public void run() {
final Bootstrap bootstrap = ApnsChannelFactory.this.bootstrapTemplate.clone()
.channelFactory(new AugmentingReflectiveChannelFactory<>(
ClientChannelClassUtil.getSocketChannelClass(ApnsChannelFactory.this.bootstrapTemplate.config().group()),
CHANNEL_READY_PROMISE_ATTRIBUTE_KEY, channelReadyPromise));
final ChannelFuture connectFuture = bootstrap.connect();
connectFuture.addListener(new GenericFutureListener<ChannelFuture>() {
@Override
public void operationComplete(final ChannelFuture future) {
if (!future.isSuccess()) {
// This may seem spurious, but our goal here is to accurately report the cause of
// connection failure; if we just wait for connection closure, we won't be able to
// tell callers anything more specific about what went wrong.
tryFailureAndLogRejectedCause(channelReadyPromise, future.cause());
}
}
});
connectFuture.channel().closeFuture().addListener(new GenericFutureListener<ChannelFuture> () {
@Override
public void operationComplete(final ChannelFuture future) {
// We always want to try to fail the "channel ready" promise if the connection closes; if it has
// already succeeded, this will have no effect.
channelReadyPromise.tryFailure(
new IllegalStateException("Channel closed before HTTP/2 preface completed."));
}
});
}
}, delay, TimeUnit.SECONDS);
return channelReadyPromise;
} | java | @Override
public Future<Channel> create(final Promise<Channel> channelReadyPromise) {
final long delay = this.currentDelaySeconds.get();
channelReadyPromise.addListener(new GenericFutureListener<Future<Channel>>() {
@Override
public void operationComplete(final Future<Channel> future) {
final long updatedDelay = future.isSuccess() ? 0 :
Math.max(Math.min(delay * 2, MAX_CONNECT_DELAY_SECONDS), MIN_CONNECT_DELAY_SECONDS);
ApnsChannelFactory.this.currentDelaySeconds.compareAndSet(delay, updatedDelay);
}
});
this.bootstrapTemplate.config().group().schedule(new Runnable() {
@Override
public void run() {
final Bootstrap bootstrap = ApnsChannelFactory.this.bootstrapTemplate.clone()
.channelFactory(new AugmentingReflectiveChannelFactory<>(
ClientChannelClassUtil.getSocketChannelClass(ApnsChannelFactory.this.bootstrapTemplate.config().group()),
CHANNEL_READY_PROMISE_ATTRIBUTE_KEY, channelReadyPromise));
final ChannelFuture connectFuture = bootstrap.connect();
connectFuture.addListener(new GenericFutureListener<ChannelFuture>() {
@Override
public void operationComplete(final ChannelFuture future) {
if (!future.isSuccess()) {
// This may seem spurious, but our goal here is to accurately report the cause of
// connection failure; if we just wait for connection closure, we won't be able to
// tell callers anything more specific about what went wrong.
tryFailureAndLogRejectedCause(channelReadyPromise, future.cause());
}
}
});
connectFuture.channel().closeFuture().addListener(new GenericFutureListener<ChannelFuture> () {
@Override
public void operationComplete(final ChannelFuture future) {
// We always want to try to fail the "channel ready" promise if the connection closes; if it has
// already succeeded, this will have no effect.
channelReadyPromise.tryFailure(
new IllegalStateException("Channel closed before HTTP/2 preface completed."));
}
});
}
}, delay, TimeUnit.SECONDS);
return channelReadyPromise;
} | [
"@",
"Override",
"public",
"Future",
"<",
"Channel",
">",
"create",
"(",
"final",
"Promise",
"<",
"Channel",
">",
"channelReadyPromise",
")",
"{",
"final",
"long",
"delay",
"=",
"this",
".",
"currentDelaySeconds",
".",
"get",
"(",
")",
";",
"channelReadyPromise",
".",
"addListener",
"(",
"new",
"GenericFutureListener",
"<",
"Future",
"<",
"Channel",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"operationComplete",
"(",
"final",
"Future",
"<",
"Channel",
">",
"future",
")",
"{",
"final",
"long",
"updatedDelay",
"=",
"future",
".",
"isSuccess",
"(",
")",
"?",
"0",
":",
"Math",
".",
"max",
"(",
"Math",
".",
"min",
"(",
"delay",
"*",
"2",
",",
"MAX_CONNECT_DELAY_SECONDS",
")",
",",
"MIN_CONNECT_DELAY_SECONDS",
")",
";",
"ApnsChannelFactory",
".",
"this",
".",
"currentDelaySeconds",
".",
"compareAndSet",
"(",
"delay",
",",
"updatedDelay",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"bootstrapTemplate",
".",
"config",
"(",
")",
".",
"group",
"(",
")",
".",
"schedule",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"final",
"Bootstrap",
"bootstrap",
"=",
"ApnsChannelFactory",
".",
"this",
".",
"bootstrapTemplate",
".",
"clone",
"(",
")",
".",
"channelFactory",
"(",
"new",
"AugmentingReflectiveChannelFactory",
"<>",
"(",
"ClientChannelClassUtil",
".",
"getSocketChannelClass",
"(",
"ApnsChannelFactory",
".",
"this",
".",
"bootstrapTemplate",
".",
"config",
"(",
")",
".",
"group",
"(",
")",
")",
",",
"CHANNEL_READY_PROMISE_ATTRIBUTE_KEY",
",",
"channelReadyPromise",
")",
")",
";",
"final",
"ChannelFuture",
"connectFuture",
"=",
"bootstrap",
".",
"connect",
"(",
")",
";",
"connectFuture",
".",
"addListener",
"(",
"new",
"GenericFutureListener",
"<",
"ChannelFuture",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"operationComplete",
"(",
"final",
"ChannelFuture",
"future",
")",
"{",
"if",
"(",
"!",
"future",
".",
"isSuccess",
"(",
")",
")",
"{",
"// This may seem spurious, but our goal here is to accurately report the cause of",
"// connection failure; if we just wait for connection closure, we won't be able to",
"// tell callers anything more specific about what went wrong.",
"tryFailureAndLogRejectedCause",
"(",
"channelReadyPromise",
",",
"future",
".",
"cause",
"(",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"connectFuture",
".",
"channel",
"(",
")",
".",
"closeFuture",
"(",
")",
".",
"addListener",
"(",
"new",
"GenericFutureListener",
"<",
"ChannelFuture",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"operationComplete",
"(",
"final",
"ChannelFuture",
"future",
")",
"{",
"// We always want to try to fail the \"channel ready\" promise if the connection closes; if it has",
"// already succeeded, this will have no effect.",
"channelReadyPromise",
".",
"tryFailure",
"(",
"new",
"IllegalStateException",
"(",
"\"Channel closed before HTTP/2 preface completed.\"",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
",",
"delay",
",",
"TimeUnit",
".",
"SECONDS",
")",
";",
"return",
"channelReadyPromise",
";",
"}"
] | Creates and connects a new channel. The initial connection attempt may be delayed to accommodate exponential
back-off requirements.
@param channelReadyPromise the promise to be notified when a channel has been created and connected to the APNs
server
@return a future that will be notified once a channel has been created and connected to the APNs server | [
"Creates",
"and",
"connects",
"a",
"new",
"channel",
".",
"The",
"initial",
"connection",
"attempt",
"may",
"be",
"delayed",
"to",
"accommodate",
"exponential",
"back",
"-",
"off",
"requirements",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/ApnsChannelFactory.java#L183-L239 |
29,258 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/ApnsChannelFactory.java | ApnsChannelFactory.destroy | @Override
public Future<Void> destroy(final Channel channel, final Promise<Void> promise) {
channel.close().addListener(new PromiseNotifier<>(promise));
return promise;
} | java | @Override
public Future<Void> destroy(final Channel channel, final Promise<Void> promise) {
channel.close().addListener(new PromiseNotifier<>(promise));
return promise;
} | [
"@",
"Override",
"public",
"Future",
"<",
"Void",
">",
"destroy",
"(",
"final",
"Channel",
"channel",
",",
"final",
"Promise",
"<",
"Void",
">",
"promise",
")",
"{",
"channel",
".",
"close",
"(",
")",
".",
"addListener",
"(",
"new",
"PromiseNotifier",
"<>",
"(",
"promise",
")",
")",
";",
"return",
"promise",
";",
"}"
] | Destroys a channel by closing it.
@param channel the channel to destroy
@param promise the promise to notify when the channel has been destroyed
@return a future that will be notified when the channel has been destroyed | [
"Destroys",
"a",
"channel",
"by",
"closing",
"it",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/ApnsChannelFactory.java#L249-L253 |
29,259 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/auth/AuthenticationToken.java | AuthenticationToken.verifySignature | public boolean verifySignature(final ApnsVerificationKey verificationKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
if (!this.header.getKeyId().equals(verificationKey.getKeyId())) {
return false;
}
if (!this.claims.getIssuer().equals(verificationKey.getTeamId())) {
return false;
}
final byte[] headerAndClaimsBytes;
final String headerJson = GSON.toJson(this.header);
final String claimsJson = GSON.toJson(this.claims);
final String encodedHeaderAndClaims =
encodeUnpaddedBase64UrlString(headerJson.getBytes(StandardCharsets.US_ASCII)) + '.' +
encodeUnpaddedBase64UrlString(claimsJson.getBytes(StandardCharsets.US_ASCII));
headerAndClaimsBytes = encodedHeaderAndClaims.getBytes(StandardCharsets.US_ASCII);
final Signature signature = Signature.getInstance(ApnsKey.APNS_SIGNATURE_ALGORITHM);
signature.initVerify(verificationKey);
signature.update(headerAndClaimsBytes);
return signature.verify(this.signatureBytes);
} | java | public boolean verifySignature(final ApnsVerificationKey verificationKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
if (!this.header.getKeyId().equals(verificationKey.getKeyId())) {
return false;
}
if (!this.claims.getIssuer().equals(verificationKey.getTeamId())) {
return false;
}
final byte[] headerAndClaimsBytes;
final String headerJson = GSON.toJson(this.header);
final String claimsJson = GSON.toJson(this.claims);
final String encodedHeaderAndClaims =
encodeUnpaddedBase64UrlString(headerJson.getBytes(StandardCharsets.US_ASCII)) + '.' +
encodeUnpaddedBase64UrlString(claimsJson.getBytes(StandardCharsets.US_ASCII));
headerAndClaimsBytes = encodedHeaderAndClaims.getBytes(StandardCharsets.US_ASCII);
final Signature signature = Signature.getInstance(ApnsKey.APNS_SIGNATURE_ALGORITHM);
signature.initVerify(verificationKey);
signature.update(headerAndClaimsBytes);
return signature.verify(this.signatureBytes);
} | [
"public",
"boolean",
"verifySignature",
"(",
"final",
"ApnsVerificationKey",
"verificationKey",
")",
"throws",
"NoSuchAlgorithmException",
",",
"InvalidKeyException",
",",
"SignatureException",
"{",
"if",
"(",
"!",
"this",
".",
"header",
".",
"getKeyId",
"(",
")",
".",
"equals",
"(",
"verificationKey",
".",
"getKeyId",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"this",
".",
"claims",
".",
"getIssuer",
"(",
")",
".",
"equals",
"(",
"verificationKey",
".",
"getTeamId",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"final",
"byte",
"[",
"]",
"headerAndClaimsBytes",
";",
"final",
"String",
"headerJson",
"=",
"GSON",
".",
"toJson",
"(",
"this",
".",
"header",
")",
";",
"final",
"String",
"claimsJson",
"=",
"GSON",
".",
"toJson",
"(",
"this",
".",
"claims",
")",
";",
"final",
"String",
"encodedHeaderAndClaims",
"=",
"encodeUnpaddedBase64UrlString",
"(",
"headerJson",
".",
"getBytes",
"(",
"StandardCharsets",
".",
"US_ASCII",
")",
")",
"+",
"'",
"'",
"+",
"encodeUnpaddedBase64UrlString",
"(",
"claimsJson",
".",
"getBytes",
"(",
"StandardCharsets",
".",
"US_ASCII",
")",
")",
";",
"headerAndClaimsBytes",
"=",
"encodedHeaderAndClaims",
".",
"getBytes",
"(",
"StandardCharsets",
".",
"US_ASCII",
")",
";",
"final",
"Signature",
"signature",
"=",
"Signature",
".",
"getInstance",
"(",
"ApnsKey",
".",
"APNS_SIGNATURE_ALGORITHM",
")",
";",
"signature",
".",
"initVerify",
"(",
"verificationKey",
")",
";",
"signature",
".",
"update",
"(",
"headerAndClaimsBytes",
")",
";",
"return",
"signature",
".",
"verify",
"(",
"this",
".",
"signatureBytes",
")",
";",
"}"
] | Verifies the cryptographic signature of this authentication token.
@param verificationKey the verification key (public key) to be used to verify this token's signature
@return {@code true} if this token's signature was verified or {@code false} otherwise
@throws NoSuchAlgorithmException if the JVM doesn't support the
{@value com.turo.pushy.apns.auth.ApnsKey#APNS_SIGNATURE_ALGORITHM} algorithm
@throws InvalidKeyException if the given key was invalid for any reason
@throws SignatureException if the given key could not be used to verify the token's signature | [
"Verifies",
"the",
"cryptographic",
"signature",
"of",
"this",
"authentication",
"token",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/auth/AuthenticationToken.java#L222-L247 |
29,260 | relayrides/pushy | micrometer-metrics-listener/src/main/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListener.java | MicrometerApnsClientMetricsListener.handleWriteFailure | @Override
public void handleWriteFailure(final ApnsClient apnsClient, final long notificationId) {
this.notificationStartTimes.remove(notificationId);
this.writeFailures.increment();
} | java | @Override
public void handleWriteFailure(final ApnsClient apnsClient, final long notificationId) {
this.notificationStartTimes.remove(notificationId);
this.writeFailures.increment();
} | [
"@",
"Override",
"public",
"void",
"handleWriteFailure",
"(",
"final",
"ApnsClient",
"apnsClient",
",",
"final",
"long",
"notificationId",
")",
"{",
"this",
".",
"notificationStartTimes",
".",
"remove",
"(",
"notificationId",
")",
";",
"this",
".",
"writeFailures",
".",
"increment",
"(",
")",
";",
"}"
] | Records a failed attempt to send a notification and updates metrics accordingly.
@param apnsClient the client that failed to write the notification; note that this is ignored by
{@code MicrometerApnsClientMetricsListener} instances, which should always be used for exactly one client
@param notificationId an opaque, unique identifier for the notification that could not be written | [
"Records",
"a",
"failed",
"attempt",
"to",
"send",
"a",
"notification",
"and",
"updates",
"metrics",
"accordingly",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/micrometer-metrics-listener/src/main/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListener.java#L183-L187 |
29,261 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/auth/ApnsVerificationKey.java | ApnsVerificationKey.loadFromInputStream | public static ApnsVerificationKey loadFromInputStream(final InputStream inputStream, final String teamId, final String keyId) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
final ECPublicKey verificationKey;
{
final String base64EncodedPublicKey;
{
final StringBuilder publicKeyBuilder = new StringBuilder();
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
boolean haveReadHeader = false;
boolean haveReadFooter = false;
for (String line; (line = reader.readLine()) != null; ) {
if (!haveReadHeader) {
if (line.contains("BEGIN PUBLIC KEY")) {
haveReadHeader = true;
}
} else {
if (line.contains("END PUBLIC KEY")) {
haveReadFooter = true;
break;
} else {
publicKeyBuilder.append(line);
}
}
}
if (!(haveReadHeader && haveReadFooter)) {
throw new IOException("Could not find public key header/footer");
}
base64EncodedPublicKey = publicKeyBuilder.toString();
}
final byte[] keyBytes = decodeBase64EncodedString(base64EncodedPublicKey);
final X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
final KeyFactory keyFactory = KeyFactory.getInstance("EC");
try {
verificationKey = (ECPublicKey) keyFactory.generatePublic(keySpec);
} catch (InvalidKeySpecException e) {
throw new InvalidKeyException(e);
}
}
return new ApnsVerificationKey(keyId, teamId, verificationKey);
} | java | public static ApnsVerificationKey loadFromInputStream(final InputStream inputStream, final String teamId, final String keyId) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
final ECPublicKey verificationKey;
{
final String base64EncodedPublicKey;
{
final StringBuilder publicKeyBuilder = new StringBuilder();
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
boolean haveReadHeader = false;
boolean haveReadFooter = false;
for (String line; (line = reader.readLine()) != null; ) {
if (!haveReadHeader) {
if (line.contains("BEGIN PUBLIC KEY")) {
haveReadHeader = true;
}
} else {
if (line.contains("END PUBLIC KEY")) {
haveReadFooter = true;
break;
} else {
publicKeyBuilder.append(line);
}
}
}
if (!(haveReadHeader && haveReadFooter)) {
throw new IOException("Could not find public key header/footer");
}
base64EncodedPublicKey = publicKeyBuilder.toString();
}
final byte[] keyBytes = decodeBase64EncodedString(base64EncodedPublicKey);
final X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
final KeyFactory keyFactory = KeyFactory.getInstance("EC");
try {
verificationKey = (ECPublicKey) keyFactory.generatePublic(keySpec);
} catch (InvalidKeySpecException e) {
throw new InvalidKeyException(e);
}
}
return new ApnsVerificationKey(keyId, teamId, verificationKey);
} | [
"public",
"static",
"ApnsVerificationKey",
"loadFromInputStream",
"(",
"final",
"InputStream",
"inputStream",
",",
"final",
"String",
"teamId",
",",
"final",
"String",
"keyId",
")",
"throws",
"IOException",
",",
"NoSuchAlgorithmException",
",",
"InvalidKeyException",
"{",
"final",
"ECPublicKey",
"verificationKey",
";",
"{",
"final",
"String",
"base64EncodedPublicKey",
";",
"{",
"final",
"StringBuilder",
"publicKeyBuilder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"final",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"inputStream",
")",
")",
";",
"boolean",
"haveReadHeader",
"=",
"false",
";",
"boolean",
"haveReadFooter",
"=",
"false",
";",
"for",
"(",
"String",
"line",
";",
"(",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
";",
")",
"{",
"if",
"(",
"!",
"haveReadHeader",
")",
"{",
"if",
"(",
"line",
".",
"contains",
"(",
"\"BEGIN PUBLIC KEY\"",
")",
")",
"{",
"haveReadHeader",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"line",
".",
"contains",
"(",
"\"END PUBLIC KEY\"",
")",
")",
"{",
"haveReadFooter",
"=",
"true",
";",
"break",
";",
"}",
"else",
"{",
"publicKeyBuilder",
".",
"append",
"(",
"line",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"(",
"haveReadHeader",
"&&",
"haveReadFooter",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not find public key header/footer\"",
")",
";",
"}",
"base64EncodedPublicKey",
"=",
"publicKeyBuilder",
".",
"toString",
"(",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"keyBytes",
"=",
"decodeBase64EncodedString",
"(",
"base64EncodedPublicKey",
")",
";",
"final",
"X509EncodedKeySpec",
"keySpec",
"=",
"new",
"X509EncodedKeySpec",
"(",
"keyBytes",
")",
";",
"final",
"KeyFactory",
"keyFactory",
"=",
"KeyFactory",
".",
"getInstance",
"(",
"\"EC\"",
")",
";",
"try",
"{",
"verificationKey",
"=",
"(",
"ECPublicKey",
")",
"keyFactory",
".",
"generatePublic",
"(",
"keySpec",
")",
";",
"}",
"catch",
"(",
"InvalidKeySpecException",
"e",
")",
"{",
"throw",
"new",
"InvalidKeyException",
"(",
"e",
")",
";",
"}",
"}",
"return",
"new",
"ApnsVerificationKey",
"(",
"keyId",
",",
"teamId",
",",
"verificationKey",
")",
";",
"}"
] | Loads a verification key from the given input stream.
@param inputStream the input stream from which to load the key
@param teamId the ten-character, Apple-issued identifier for the team to which the key belongs
@param keyId the ten-character, Apple-issued identitifier for the key itself
@return an APNs verification key with the given key ID and associated with the given team
@throws IOException if a key could not be loaded from the given file for any reason
@throws NoSuchAlgorithmException if the JVM does not support elliptic curve keys
@throws InvalidKeyException if the loaded key is invalid for any reason | [
"Loads",
"a",
"verification",
"key",
"from",
"the",
"given",
"input",
"stream",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/auth/ApnsVerificationKey.java#L131-L177 |
29,262 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/auth/ApnsSigningKey.java | ApnsSigningKey.loadFromInputStream | public static ApnsSigningKey loadFromInputStream(final InputStream inputStream, final String teamId, final String keyId) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
final ECPrivateKey signingKey;
{
final String base64EncodedPrivateKey;
{
final StringBuilder privateKeyBuilder = new StringBuilder();
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
boolean haveReadHeader = false;
boolean haveReadFooter = false;
for (String line; (line = reader.readLine()) != null; ) {
if (!haveReadHeader) {
if (line.contains("BEGIN PRIVATE KEY")) {
haveReadHeader = true;
}
} else {
if (line.contains("END PRIVATE KEY")) {
haveReadFooter = true;
break;
} else {
privateKeyBuilder.append(line);
}
}
}
if (!(haveReadHeader && haveReadFooter)) {
throw new IOException("Could not find private key header/footer");
}
base64EncodedPrivateKey = privateKeyBuilder.toString();
}
final byte[] keyBytes = decodeBase64EncodedString(base64EncodedPrivateKey);
final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
final KeyFactory keyFactory = KeyFactory.getInstance("EC");
try {
signingKey = (ECPrivateKey) keyFactory.generatePrivate(keySpec);
} catch (InvalidKeySpecException e) {
throw new InvalidKeyException(e);
}
}
return new ApnsSigningKey(keyId, teamId, signingKey);
} | java | public static ApnsSigningKey loadFromInputStream(final InputStream inputStream, final String teamId, final String keyId) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
final ECPrivateKey signingKey;
{
final String base64EncodedPrivateKey;
{
final StringBuilder privateKeyBuilder = new StringBuilder();
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
boolean haveReadHeader = false;
boolean haveReadFooter = false;
for (String line; (line = reader.readLine()) != null; ) {
if (!haveReadHeader) {
if (line.contains("BEGIN PRIVATE KEY")) {
haveReadHeader = true;
}
} else {
if (line.contains("END PRIVATE KEY")) {
haveReadFooter = true;
break;
} else {
privateKeyBuilder.append(line);
}
}
}
if (!(haveReadHeader && haveReadFooter)) {
throw new IOException("Could not find private key header/footer");
}
base64EncodedPrivateKey = privateKeyBuilder.toString();
}
final byte[] keyBytes = decodeBase64EncodedString(base64EncodedPrivateKey);
final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
final KeyFactory keyFactory = KeyFactory.getInstance("EC");
try {
signingKey = (ECPrivateKey) keyFactory.generatePrivate(keySpec);
} catch (InvalidKeySpecException e) {
throw new InvalidKeyException(e);
}
}
return new ApnsSigningKey(keyId, teamId, signingKey);
} | [
"public",
"static",
"ApnsSigningKey",
"loadFromInputStream",
"(",
"final",
"InputStream",
"inputStream",
",",
"final",
"String",
"teamId",
",",
"final",
"String",
"keyId",
")",
"throws",
"IOException",
",",
"NoSuchAlgorithmException",
",",
"InvalidKeyException",
"{",
"final",
"ECPrivateKey",
"signingKey",
";",
"{",
"final",
"String",
"base64EncodedPrivateKey",
";",
"{",
"final",
"StringBuilder",
"privateKeyBuilder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"final",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"inputStream",
")",
")",
";",
"boolean",
"haveReadHeader",
"=",
"false",
";",
"boolean",
"haveReadFooter",
"=",
"false",
";",
"for",
"(",
"String",
"line",
";",
"(",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
";",
")",
"{",
"if",
"(",
"!",
"haveReadHeader",
")",
"{",
"if",
"(",
"line",
".",
"contains",
"(",
"\"BEGIN PRIVATE KEY\"",
")",
")",
"{",
"haveReadHeader",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"line",
".",
"contains",
"(",
"\"END PRIVATE KEY\"",
")",
")",
"{",
"haveReadFooter",
"=",
"true",
";",
"break",
";",
"}",
"else",
"{",
"privateKeyBuilder",
".",
"append",
"(",
"line",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"(",
"haveReadHeader",
"&&",
"haveReadFooter",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not find private key header/footer\"",
")",
";",
"}",
"base64EncodedPrivateKey",
"=",
"privateKeyBuilder",
".",
"toString",
"(",
")",
";",
"}",
"final",
"byte",
"[",
"]",
"keyBytes",
"=",
"decodeBase64EncodedString",
"(",
"base64EncodedPrivateKey",
")",
";",
"final",
"PKCS8EncodedKeySpec",
"keySpec",
"=",
"new",
"PKCS8EncodedKeySpec",
"(",
"keyBytes",
")",
";",
"final",
"KeyFactory",
"keyFactory",
"=",
"KeyFactory",
".",
"getInstance",
"(",
"\"EC\"",
")",
";",
"try",
"{",
"signingKey",
"=",
"(",
"ECPrivateKey",
")",
"keyFactory",
".",
"generatePrivate",
"(",
"keySpec",
")",
";",
"}",
"catch",
"(",
"InvalidKeySpecException",
"e",
")",
"{",
"throw",
"new",
"InvalidKeyException",
"(",
"e",
")",
";",
"}",
"}",
"return",
"new",
"ApnsSigningKey",
"(",
"keyId",
",",
"teamId",
",",
"signingKey",
")",
";",
"}"
] | Loads a signing key from the given input stream.
@param inputStream the input stream from which to load the key
@param teamId the ten-character, Apple-issued identifier for the team to which the key belongs
@param keyId the ten-character, Apple-issued identitifier for the key itself
@return an APNs signing key with the given key ID and associated with the given team
@throws IOException if a key could not be loaded from the given file for any reason
@throws NoSuchAlgorithmException if the JVM does not support elliptic curve keys
@throws InvalidKeyException if the loaded key is invalid for any reason | [
"Loads",
"a",
"signing",
"key",
"from",
"the",
"given",
"input",
"stream",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/auth/ApnsSigningKey.java#L124-L170 |
29,263 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/server/AcceptAllPushNotificationHandlerFactory.java | AcceptAllPushNotificationHandlerFactory.buildHandler | @Override
public PushNotificationHandler buildHandler(final SSLSession sslSession) {
return new PushNotificationHandler() {
@Override
public void handlePushNotification(final Http2Headers headers, final ByteBuf payload) {
// Accept everything unconditionally!
}
};
} | java | @Override
public PushNotificationHandler buildHandler(final SSLSession sslSession) {
return new PushNotificationHandler() {
@Override
public void handlePushNotification(final Http2Headers headers, final ByteBuf payload) {
// Accept everything unconditionally!
}
};
} | [
"@",
"Override",
"public",
"PushNotificationHandler",
"buildHandler",
"(",
"final",
"SSLSession",
"sslSession",
")",
"{",
"return",
"new",
"PushNotificationHandler",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"handlePushNotification",
"(",
"final",
"Http2Headers",
"headers",
",",
"final",
"ByteBuf",
"payload",
")",
"{",
"// Accept everything unconditionally!",
"}",
"}",
";",
"}"
] | Constructs a new push notification handler that unconditionally accepts all push notifications.
@param sslSession the SSL session associated with the channel for which this handler will handle notifications
@return a new "accept everything" push notification handler | [
"Constructs",
"a",
"new",
"push",
"notification",
"handler",
"that",
"unconditionally",
"accepts",
"all",
"push",
"notifications",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/server/AcceptAllPushNotificationHandlerFactory.java#L48-L57 |
29,264 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/ApnsChannelPool.java | ApnsChannelPool.release | void release(final Channel channel) {
if (this.executor.inEventLoop()) {
this.releaseWithinEventExecutor(channel);
} else {
this.executor.submit(new Runnable() {
@Override
public void run() {
ApnsChannelPool.this.releaseWithinEventExecutor(channel);
}
});
}
} | java | void release(final Channel channel) {
if (this.executor.inEventLoop()) {
this.releaseWithinEventExecutor(channel);
} else {
this.executor.submit(new Runnable() {
@Override
public void run() {
ApnsChannelPool.this.releaseWithinEventExecutor(channel);
}
});
}
} | [
"void",
"release",
"(",
"final",
"Channel",
"channel",
")",
"{",
"if",
"(",
"this",
".",
"executor",
".",
"inEventLoop",
"(",
")",
")",
"{",
"this",
".",
"releaseWithinEventExecutor",
"(",
"channel",
")",
";",
"}",
"else",
"{",
"this",
".",
"executor",
".",
"submit",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"ApnsChannelPool",
".",
"this",
".",
"releaseWithinEventExecutor",
"(",
"channel",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | Returns a previously-acquired channel to the pool.
@param channel the channel to return to the pool | [
"Returns",
"a",
"previously",
"-",
"acquired",
"channel",
"to",
"the",
"pool",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/ApnsChannelPool.java#L205-L216 |
29,265 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/ApnsChannelPool.java | ApnsChannelPool.close | public Future<Void> close() {
return this.allChannels.close().addListener(new GenericFutureListener<Future<Void>>() {
@Override
public void operationComplete(final Future<Void> future) throws Exception {
ApnsChannelPool.this.isClosed = true;
if (ApnsChannelPool.this.channelFactory instanceof Closeable) {
((Closeable) ApnsChannelPool.this.channelFactory).close();
}
for (final Promise<Channel> acquisitionPromise : ApnsChannelPool.this.pendingAcquisitionPromises) {
acquisitionPromise.tryFailure(POOL_CLOSED_EXCEPTION);
}
}
});
} | java | public Future<Void> close() {
return this.allChannels.close().addListener(new GenericFutureListener<Future<Void>>() {
@Override
public void operationComplete(final Future<Void> future) throws Exception {
ApnsChannelPool.this.isClosed = true;
if (ApnsChannelPool.this.channelFactory instanceof Closeable) {
((Closeable) ApnsChannelPool.this.channelFactory).close();
}
for (final Promise<Channel> acquisitionPromise : ApnsChannelPool.this.pendingAcquisitionPromises) {
acquisitionPromise.tryFailure(POOL_CLOSED_EXCEPTION);
}
}
});
} | [
"public",
"Future",
"<",
"Void",
">",
"close",
"(",
")",
"{",
"return",
"this",
".",
"allChannels",
".",
"close",
"(",
")",
".",
"addListener",
"(",
"new",
"GenericFutureListener",
"<",
"Future",
"<",
"Void",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"operationComplete",
"(",
"final",
"Future",
"<",
"Void",
">",
"future",
")",
"throws",
"Exception",
"{",
"ApnsChannelPool",
".",
"this",
".",
"isClosed",
"=",
"true",
";",
"if",
"(",
"ApnsChannelPool",
".",
"this",
".",
"channelFactory",
"instanceof",
"Closeable",
")",
"{",
"(",
"(",
"Closeable",
")",
"ApnsChannelPool",
".",
"this",
".",
"channelFactory",
")",
".",
"close",
"(",
")",
";",
"}",
"for",
"(",
"final",
"Promise",
"<",
"Channel",
">",
"acquisitionPromise",
":",
"ApnsChannelPool",
".",
"this",
".",
"pendingAcquisitionPromises",
")",
"{",
"acquisitionPromise",
".",
"tryFailure",
"(",
"POOL_CLOSED_EXCEPTION",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Shuts down this channel pool and releases all retained resources.
@return a {@code Future} that will be completed when all resources held by this pool have been released | [
"Shuts",
"down",
"this",
"channel",
"pool",
"and",
"releases",
"all",
"retained",
"resources",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/ApnsChannelPool.java#L256-L271 |
29,266 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/server/BaseHttp2ServerBuilder.java | BaseHttp2ServerBuilder.build | public T build() throws SSLException {
final SslContext sslContext;
{
final SslProvider sslProvider;
if (OpenSsl.isAvailable()) {
log.info("Native SSL provider is available; will use native provider.");
sslProvider = SslProvider.OPENSSL;
} else {
log.info("Native SSL provider not available; will use JDK SSL provider.");
sslProvider = SslProvider.JDK;
}
final SslContextBuilder sslContextBuilder;
if (this.certificateChain != null && this.privateKey != null) {
sslContextBuilder = SslContextBuilder.forServer(this.privateKey, this.privateKeyPassword, this.certificateChain);
} else if (this.certificateChainPemFile != null && this.privateKeyPkcs8File != null) {
sslContextBuilder = SslContextBuilder.forServer(this.certificateChainPemFile, this.privateKeyPkcs8File, this.privateKeyPassword);
} else if (this.certificateChainInputStream != null && this.privateKeyPkcs8InputStream != null) {
sslContextBuilder = SslContextBuilder.forServer(this.certificateChainInputStream, this.privateKeyPkcs8InputStream, this.privateKeyPassword);
} else {
throw new IllegalStateException("Must specify server credentials before building a mock server.");
}
sslContextBuilder.sslProvider(sslProvider)
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
.clientAuth(ClientAuth.OPTIONAL);
if (this.trustedClientCertificatePemFile != null) {
sslContextBuilder.trustManager(this.trustedClientCertificatePemFile);
} else if (this.trustedClientCertificateInputStream != null) {
sslContextBuilder.trustManager(this.trustedClientCertificateInputStream);
} else if (this.trustedClientCertificates != null) {
sslContextBuilder.trustManager(this.trustedClientCertificates);
}
if (this.useAlpn) {
sslContextBuilder.applicationProtocolConfig(new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN,
ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2));
}
sslContext = sslContextBuilder.build();
}
final T server = this.constructServer(sslContext);
if (sslContext instanceof ReferenceCounted) {
((ReferenceCounted) sslContext).release();
}
return server;
} | java | public T build() throws SSLException {
final SslContext sslContext;
{
final SslProvider sslProvider;
if (OpenSsl.isAvailable()) {
log.info("Native SSL provider is available; will use native provider.");
sslProvider = SslProvider.OPENSSL;
} else {
log.info("Native SSL provider not available; will use JDK SSL provider.");
sslProvider = SslProvider.JDK;
}
final SslContextBuilder sslContextBuilder;
if (this.certificateChain != null && this.privateKey != null) {
sslContextBuilder = SslContextBuilder.forServer(this.privateKey, this.privateKeyPassword, this.certificateChain);
} else if (this.certificateChainPemFile != null && this.privateKeyPkcs8File != null) {
sslContextBuilder = SslContextBuilder.forServer(this.certificateChainPemFile, this.privateKeyPkcs8File, this.privateKeyPassword);
} else if (this.certificateChainInputStream != null && this.privateKeyPkcs8InputStream != null) {
sslContextBuilder = SslContextBuilder.forServer(this.certificateChainInputStream, this.privateKeyPkcs8InputStream, this.privateKeyPassword);
} else {
throw new IllegalStateException("Must specify server credentials before building a mock server.");
}
sslContextBuilder.sslProvider(sslProvider)
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
.clientAuth(ClientAuth.OPTIONAL);
if (this.trustedClientCertificatePemFile != null) {
sslContextBuilder.trustManager(this.trustedClientCertificatePemFile);
} else if (this.trustedClientCertificateInputStream != null) {
sslContextBuilder.trustManager(this.trustedClientCertificateInputStream);
} else if (this.trustedClientCertificates != null) {
sslContextBuilder.trustManager(this.trustedClientCertificates);
}
if (this.useAlpn) {
sslContextBuilder.applicationProtocolConfig(new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN,
ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2));
}
sslContext = sslContextBuilder.build();
}
final T server = this.constructServer(sslContext);
if (sslContext instanceof ReferenceCounted) {
((ReferenceCounted) sslContext).release();
}
return server;
} | [
"public",
"T",
"build",
"(",
")",
"throws",
"SSLException",
"{",
"final",
"SslContext",
"sslContext",
";",
"{",
"final",
"SslProvider",
"sslProvider",
";",
"if",
"(",
"OpenSsl",
".",
"isAvailable",
"(",
")",
")",
"{",
"log",
".",
"info",
"(",
"\"Native SSL provider is available; will use native provider.\"",
")",
";",
"sslProvider",
"=",
"SslProvider",
".",
"OPENSSL",
";",
"}",
"else",
"{",
"log",
".",
"info",
"(",
"\"Native SSL provider not available; will use JDK SSL provider.\"",
")",
";",
"sslProvider",
"=",
"SslProvider",
".",
"JDK",
";",
"}",
"final",
"SslContextBuilder",
"sslContextBuilder",
";",
"if",
"(",
"this",
".",
"certificateChain",
"!=",
"null",
"&&",
"this",
".",
"privateKey",
"!=",
"null",
")",
"{",
"sslContextBuilder",
"=",
"SslContextBuilder",
".",
"forServer",
"(",
"this",
".",
"privateKey",
",",
"this",
".",
"privateKeyPassword",
",",
"this",
".",
"certificateChain",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"certificateChainPemFile",
"!=",
"null",
"&&",
"this",
".",
"privateKeyPkcs8File",
"!=",
"null",
")",
"{",
"sslContextBuilder",
"=",
"SslContextBuilder",
".",
"forServer",
"(",
"this",
".",
"certificateChainPemFile",
",",
"this",
".",
"privateKeyPkcs8File",
",",
"this",
".",
"privateKeyPassword",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"certificateChainInputStream",
"!=",
"null",
"&&",
"this",
".",
"privateKeyPkcs8InputStream",
"!=",
"null",
")",
"{",
"sslContextBuilder",
"=",
"SslContextBuilder",
".",
"forServer",
"(",
"this",
".",
"certificateChainInputStream",
",",
"this",
".",
"privateKeyPkcs8InputStream",
",",
"this",
".",
"privateKeyPassword",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Must specify server credentials before building a mock server.\"",
")",
";",
"}",
"sslContextBuilder",
".",
"sslProvider",
"(",
"sslProvider",
")",
".",
"ciphers",
"(",
"Http2SecurityUtil",
".",
"CIPHERS",
",",
"SupportedCipherSuiteFilter",
".",
"INSTANCE",
")",
".",
"clientAuth",
"(",
"ClientAuth",
".",
"OPTIONAL",
")",
";",
"if",
"(",
"this",
".",
"trustedClientCertificatePemFile",
"!=",
"null",
")",
"{",
"sslContextBuilder",
".",
"trustManager",
"(",
"this",
".",
"trustedClientCertificatePemFile",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"trustedClientCertificateInputStream",
"!=",
"null",
")",
"{",
"sslContextBuilder",
".",
"trustManager",
"(",
"this",
".",
"trustedClientCertificateInputStream",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"trustedClientCertificates",
"!=",
"null",
")",
"{",
"sslContextBuilder",
".",
"trustManager",
"(",
"this",
".",
"trustedClientCertificates",
")",
";",
"}",
"if",
"(",
"this",
".",
"useAlpn",
")",
"{",
"sslContextBuilder",
".",
"applicationProtocolConfig",
"(",
"new",
"ApplicationProtocolConfig",
"(",
"ApplicationProtocolConfig",
".",
"Protocol",
".",
"ALPN",
",",
"ApplicationProtocolConfig",
".",
"SelectorFailureBehavior",
".",
"NO_ADVERTISE",
",",
"ApplicationProtocolConfig",
".",
"SelectedListenerFailureBehavior",
".",
"ACCEPT",
",",
"ApplicationProtocolNames",
".",
"HTTP_2",
")",
")",
";",
"}",
"sslContext",
"=",
"sslContextBuilder",
".",
"build",
"(",
")",
";",
"}",
"final",
"T",
"server",
"=",
"this",
".",
"constructServer",
"(",
"sslContext",
")",
";",
"if",
"(",
"sslContext",
"instanceof",
"ReferenceCounted",
")",
"{",
"(",
"(",
"ReferenceCounted",
")",
"sslContext",
")",
".",
"release",
"(",
")",
";",
"}",
"return",
"server",
";",
"}"
] | Constructs a new server with the previously-set configuration.
@return a new server instance with the previously-set configuration
@throws SSLException if an SSL context could not be created for the new server for any reason
@since 0.8 | [
"Constructs",
"a",
"new",
"server",
"with",
"the",
"previously",
"-",
"set",
"configuration",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/server/BaseHttp2ServerBuilder.java#L285-L340 |
29,267 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/ClientChannelClassUtil.java | ClientChannelClassUtil.getSocketChannelClass | static Class<? extends SocketChannel> getSocketChannelClass(final EventLoopGroup eventLoopGroup) {
Objects.requireNonNull(eventLoopGroup);
final String socketChannelClassName = SOCKET_CHANNEL_CLASSES.get(eventLoopGroup.getClass().getName());
if (socketChannelClassName == null) {
throw new IllegalArgumentException("No socket channel class found for event loop group type: " + eventLoopGroup.getClass().getName());
}
try {
return Class.forName(socketChannelClassName).asSubclass(SocketChannel.class);
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} | java | static Class<? extends SocketChannel> getSocketChannelClass(final EventLoopGroup eventLoopGroup) {
Objects.requireNonNull(eventLoopGroup);
final String socketChannelClassName = SOCKET_CHANNEL_CLASSES.get(eventLoopGroup.getClass().getName());
if (socketChannelClassName == null) {
throw new IllegalArgumentException("No socket channel class found for event loop group type: " + eventLoopGroup.getClass().getName());
}
try {
return Class.forName(socketChannelClassName).asSubclass(SocketChannel.class);
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} | [
"static",
"Class",
"<",
"?",
"extends",
"SocketChannel",
">",
"getSocketChannelClass",
"(",
"final",
"EventLoopGroup",
"eventLoopGroup",
")",
"{",
"Objects",
".",
"requireNonNull",
"(",
"eventLoopGroup",
")",
";",
"final",
"String",
"socketChannelClassName",
"=",
"SOCKET_CHANNEL_CLASSES",
".",
"get",
"(",
"eventLoopGroup",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"socketChannelClassName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No socket channel class found for event loop group type: \"",
"+",
"eventLoopGroup",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"try",
"{",
"return",
"Class",
".",
"forName",
"(",
"socketChannelClassName",
")",
".",
"asSubclass",
"(",
"SocketChannel",
".",
"class",
")",
";",
"}",
"catch",
"(",
"final",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a socket channel class suitable for specified event loop group.
@param eventLoopGroup the event loop group for which to identify an appropriate socket channel class; must not
be {@code null}
@return a socket channel class suitable for use with the given event loop group
@throws IllegalArgumentException in case of null or unrecognized event loop group | [
"Returns",
"a",
"socket",
"channel",
"class",
"suitable",
"for",
"specified",
"event",
"loop",
"group",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/ClientChannelClassUtil.java#L60-L74 |
29,268 | relayrides/pushy | pushy/src/main/java/com/turo/pushy/apns/ClientChannelClassUtil.java | ClientChannelClassUtil.getDatagramChannelClass | static Class<? extends DatagramChannel> getDatagramChannelClass(final EventLoopGroup eventLoopGroup) {
Objects.requireNonNull(eventLoopGroup);
final String datagramChannelClassName = DATAGRAM_CHANNEL_CLASSES.get(eventLoopGroup.getClass().getName());
if (datagramChannelClassName == null) {
throw new IllegalArgumentException("No datagram channel class found for event loop group type: " + eventLoopGroup.getClass().getName());
}
try {
return Class.forName(datagramChannelClassName).asSubclass(DatagramChannel.class);
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} | java | static Class<? extends DatagramChannel> getDatagramChannelClass(final EventLoopGroup eventLoopGroup) {
Objects.requireNonNull(eventLoopGroup);
final String datagramChannelClassName = DATAGRAM_CHANNEL_CLASSES.get(eventLoopGroup.getClass().getName());
if (datagramChannelClassName == null) {
throw new IllegalArgumentException("No datagram channel class found for event loop group type: " + eventLoopGroup.getClass().getName());
}
try {
return Class.forName(datagramChannelClassName).asSubclass(DatagramChannel.class);
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
} | [
"static",
"Class",
"<",
"?",
"extends",
"DatagramChannel",
">",
"getDatagramChannelClass",
"(",
"final",
"EventLoopGroup",
"eventLoopGroup",
")",
"{",
"Objects",
".",
"requireNonNull",
"(",
"eventLoopGroup",
")",
";",
"final",
"String",
"datagramChannelClassName",
"=",
"DATAGRAM_CHANNEL_CLASSES",
".",
"get",
"(",
"eventLoopGroup",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"datagramChannelClassName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"No datagram channel class found for event loop group type: \"",
"+",
"eventLoopGroup",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"try",
"{",
"return",
"Class",
".",
"forName",
"(",
"datagramChannelClassName",
")",
".",
"asSubclass",
"(",
"DatagramChannel",
".",
"class",
")",
";",
"}",
"catch",
"(",
"final",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a datagram channel class suitable for specified event loop group.
@param eventLoopGroup the event loop group for which to identify an appropriate datagram channel class; must not
be {@code null}
@return a datagram channel class suitable for use with the given event loop group
@throws IllegalArgumentException in case of null or unrecognized event loop group | [
"Returns",
"a",
"datagram",
"channel",
"class",
"suitable",
"for",
"specified",
"event",
"loop",
"group",
"."
] | 1f6f9a0e07d785c815d74c2320a8d87c80231d36 | https://github.com/relayrides/pushy/blob/1f6f9a0e07d785c815d74c2320a8d87c80231d36/pushy/src/main/java/com/turo/pushy/apns/ClientChannelClassUtil.java#L86-L100 |
29,269 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/screen/AbstractScreen.java | AbstractScreen.setCursorPosition | @Override
public void setCursorPosition(TerminalPosition position) {
if(position == null) {
//Skip any validation checks if we just want to hide the cursor
this.cursorPosition = null;
return;
}
if(position.getColumn() < 0) {
position = position.withColumn(0);
}
if(position.getRow() < 0) {
position = position.withRow(0);
}
if(position.getColumn() >= terminalSize.getColumns()) {
position = position.withColumn(terminalSize.getColumns() - 1);
}
if(position.getRow() >= terminalSize.getRows()) {
position = position.withRow(terminalSize.getRows() - 1);
}
this.cursorPosition = position;
} | java | @Override
public void setCursorPosition(TerminalPosition position) {
if(position == null) {
//Skip any validation checks if we just want to hide the cursor
this.cursorPosition = null;
return;
}
if(position.getColumn() < 0) {
position = position.withColumn(0);
}
if(position.getRow() < 0) {
position = position.withRow(0);
}
if(position.getColumn() >= terminalSize.getColumns()) {
position = position.withColumn(terminalSize.getColumns() - 1);
}
if(position.getRow() >= terminalSize.getRows()) {
position = position.withRow(terminalSize.getRows() - 1);
}
this.cursorPosition = position;
} | [
"@",
"Override",
"public",
"void",
"setCursorPosition",
"(",
"TerminalPosition",
"position",
")",
"{",
"if",
"(",
"position",
"==",
"null",
")",
"{",
"//Skip any validation checks if we just want to hide the cursor",
"this",
".",
"cursorPosition",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"position",
".",
"getColumn",
"(",
")",
"<",
"0",
")",
"{",
"position",
"=",
"position",
".",
"withColumn",
"(",
"0",
")",
";",
"}",
"if",
"(",
"position",
".",
"getRow",
"(",
")",
"<",
"0",
")",
"{",
"position",
"=",
"position",
".",
"withRow",
"(",
"0",
")",
";",
"}",
"if",
"(",
"position",
".",
"getColumn",
"(",
")",
">=",
"terminalSize",
".",
"getColumns",
"(",
")",
")",
"{",
"position",
"=",
"position",
".",
"withColumn",
"(",
"terminalSize",
".",
"getColumns",
"(",
")",
"-",
"1",
")",
";",
"}",
"if",
"(",
"position",
".",
"getRow",
"(",
")",
">=",
"terminalSize",
".",
"getRows",
"(",
")",
")",
"{",
"position",
"=",
"position",
".",
"withRow",
"(",
"terminalSize",
".",
"getRows",
"(",
")",
"-",
"1",
")",
";",
"}",
"this",
".",
"cursorPosition",
"=",
"position",
";",
"}"
] | Moves the current cursor position or hides it. If the cursor is hidden and given a new position, it will be
visible after this method call.
@param position 0-indexed column and row numbers of the new position, or if {@code null}, hides the cursor | [
"Moves",
"the",
"current",
"cursor",
"position",
"or",
"hides",
"it",
".",
"If",
"the",
"cursor",
"is",
"hidden",
"and",
"given",
"a",
"new",
"position",
"it",
"will",
"be",
"visible",
"after",
"this",
"method",
"call",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/screen/AbstractScreen.java#L89-L109 |
29,270 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/screen/AbstractScreen.java | AbstractScreen.scrollLines | @Override
public void scrollLines(int firstLine, int lastLine, int distance) {
getBackBuffer().scrollLines(firstLine, lastLine, distance);
} | java | @Override
public void scrollLines(int firstLine, int lastLine, int distance) {
getBackBuffer().scrollLines(firstLine, lastLine, distance);
} | [
"@",
"Override",
"public",
"void",
"scrollLines",
"(",
"int",
"firstLine",
",",
"int",
"lastLine",
",",
"int",
"distance",
")",
"{",
"getBackBuffer",
"(",
")",
".",
"scrollLines",
"(",
"firstLine",
",",
"lastLine",
",",
"distance",
")",
";",
"}"
] | Performs the scrolling on its back-buffer. | [
"Performs",
"the",
"scrolling",
"on",
"its",
"back",
"-",
"buffer",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/screen/AbstractScreen.java#L265-L268 |
29,271 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/terminal/ansi/StreamBasedTerminal.java | StreamBasedTerminal.waitForCursorPositionReport | synchronized TerminalPosition waitForCursorPositionReport() throws IOException {
long startTime = System.currentTimeMillis();
TerminalPosition cursorPosition = lastReportedCursorPosition;
while(cursorPosition == null) {
if(System.currentTimeMillis() - startTime > 5000) {
//throw new IllegalStateException("Terminal didn't send any position report for 5 seconds, please file a bug with a reproduce!");
return null;
}
KeyStroke keyStroke = readInput(false, false);
if(keyStroke != null) {
keyQueue.add(keyStroke);
}
else {
try { Thread.sleep(1); } catch(InterruptedException ignored) {}
}
cursorPosition = lastReportedCursorPosition;
}
return cursorPosition;
} | java | synchronized TerminalPosition waitForCursorPositionReport() throws IOException {
long startTime = System.currentTimeMillis();
TerminalPosition cursorPosition = lastReportedCursorPosition;
while(cursorPosition == null) {
if(System.currentTimeMillis() - startTime > 5000) {
//throw new IllegalStateException("Terminal didn't send any position report for 5 seconds, please file a bug with a reproduce!");
return null;
}
KeyStroke keyStroke = readInput(false, false);
if(keyStroke != null) {
keyQueue.add(keyStroke);
}
else {
try { Thread.sleep(1); } catch(InterruptedException ignored) {}
}
cursorPosition = lastReportedCursorPosition;
}
return cursorPosition;
} | [
"synchronized",
"TerminalPosition",
"waitForCursorPositionReport",
"(",
")",
"throws",
"IOException",
"{",
"long",
"startTime",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"TerminalPosition",
"cursorPosition",
"=",
"lastReportedCursorPosition",
";",
"while",
"(",
"cursorPosition",
"==",
"null",
")",
"{",
"if",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
"-",
"startTime",
">",
"5000",
")",
"{",
"//throw new IllegalStateException(\"Terminal didn't send any position report for 5 seconds, please file a bug with a reproduce!\");",
"return",
"null",
";",
"}",
"KeyStroke",
"keyStroke",
"=",
"readInput",
"(",
"false",
",",
"false",
")",
";",
"if",
"(",
"keyStroke",
"!=",
"null",
")",
"{",
"keyQueue",
".",
"add",
"(",
"keyStroke",
")",
";",
"}",
"else",
"{",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"1",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"ignored",
")",
"{",
"}",
"}",
"cursorPosition",
"=",
"lastReportedCursorPosition",
";",
"}",
"return",
"cursorPosition",
";",
"}"
] | Waits for up to 5 seconds for a terminal cursor position report to appear in the input stream. If the timeout
expires, it will return null. You should have sent the cursor position query already before
calling this method.
@return Current position of the cursor, or null if the terminal didn't report it in time.
@throws IOException If there was an I/O error | [
"Waits",
"for",
"up",
"to",
"5",
"seconds",
"for",
"a",
"terminal",
"cursor",
"position",
"report",
"to",
"appear",
"in",
"the",
"input",
"stream",
".",
"If",
"the",
"timeout",
"expires",
"it",
"will",
"return",
"null",
".",
"You",
"should",
"have",
"sent",
"the",
"cursor",
"position",
"query",
"already",
"before",
"calling",
"this",
"method",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/terminal/ansi/StreamBasedTerminal.java#L167-L185 |
29,272 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/dialogs/MessageDialogBuilder.java | MessageDialogBuilder.setExtraWindowHints | public MessageDialogBuilder setExtraWindowHints(Collection<Window.Hint> extraWindowHints) {
this.extraWindowHints.clear();
this.extraWindowHints.addAll(extraWindowHints);
return this;
} | java | public MessageDialogBuilder setExtraWindowHints(Collection<Window.Hint> extraWindowHints) {
this.extraWindowHints.clear();
this.extraWindowHints.addAll(extraWindowHints);
return this;
} | [
"public",
"MessageDialogBuilder",
"setExtraWindowHints",
"(",
"Collection",
"<",
"Window",
".",
"Hint",
">",
"extraWindowHints",
")",
"{",
"this",
".",
"extraWindowHints",
".",
"clear",
"(",
")",
";",
"this",
".",
"extraWindowHints",
".",
"addAll",
"(",
"extraWindowHints",
")",
";",
"return",
"this",
";",
"}"
] | Assigns a set of extra window hints that you want the built dialog to have
@param extraWindowHints Window hints to assign to the window in addition to the ones the builder will put
@return Itself | [
"Assigns",
"a",
"set",
"of",
"extra",
"window",
"hints",
"that",
"you",
"want",
"the",
"built",
"dialog",
"to",
"have"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/dialogs/MessageDialogBuilder.java#L95-L99 |
29,273 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/dialogs/WaitingDialog.java | WaitingDialog.showDialog | public static WaitingDialog showDialog(WindowBasedTextGUI textGUI, String title, String text) {
WaitingDialog waitingDialog = createDialog(title, text);
waitingDialog.showDialog(textGUI, false);
return waitingDialog;
} | java | public static WaitingDialog showDialog(WindowBasedTextGUI textGUI, String title, String text) {
WaitingDialog waitingDialog = createDialog(title, text);
waitingDialog.showDialog(textGUI, false);
return waitingDialog;
} | [
"public",
"static",
"WaitingDialog",
"showDialog",
"(",
"WindowBasedTextGUI",
"textGUI",
",",
"String",
"title",
",",
"String",
"text",
")",
"{",
"WaitingDialog",
"waitingDialog",
"=",
"createDialog",
"(",
"title",
",",
"text",
")",
";",
"waitingDialog",
".",
"showDialog",
"(",
"textGUI",
",",
"false",
")",
";",
"return",
"waitingDialog",
";",
"}"
] | Creates and displays a waiting dialog without blocking for it to finish
@param textGUI GUI to add the dialog to
@param title Title of the waiting dialog
@param text Text to display on the waiting dialog
@return Created waiting dialog | [
"Creates",
"and",
"displays",
"a",
"waiting",
"dialog",
"without",
"blocking",
"for",
"it",
"to",
"finish"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/dialogs/WaitingDialog.java#L76-L80 |
29,274 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/GridLayout.java | GridLayout.createHorizontallyFilledLayoutData | public static LayoutData createHorizontallyFilledLayoutData(int horizontalSpan) {
return createLayoutData(
Alignment.FILL,
Alignment.CENTER,
true,
false,
horizontalSpan,
1);
} | java | public static LayoutData createHorizontallyFilledLayoutData(int horizontalSpan) {
return createLayoutData(
Alignment.FILL,
Alignment.CENTER,
true,
false,
horizontalSpan,
1);
} | [
"public",
"static",
"LayoutData",
"createHorizontallyFilledLayoutData",
"(",
"int",
"horizontalSpan",
")",
"{",
"return",
"createLayoutData",
"(",
"Alignment",
".",
"FILL",
",",
"Alignment",
".",
"CENTER",
",",
"true",
",",
"false",
",",
"horizontalSpan",
",",
"1",
")",
";",
"}"
] | This is a shortcut method that will create a grid layout data object that will expand its cell as much as is can
horizontally and make the component occupy the whole area horizontally and center it vertically
@param horizontalSpan How many cells to span horizontally
@return Layout data object with the specified span and horizontally expanding as much as it can | [
"This",
"is",
"a",
"shortcut",
"method",
"that",
"will",
"create",
"a",
"grid",
"layout",
"data",
"object",
"that",
"will",
"expand",
"its",
"cell",
"as",
"much",
"as",
"is",
"can",
"horizontally",
"and",
"make",
"the",
"component",
"occupy",
"the",
"whole",
"area",
"horizontally",
"and",
"center",
"it",
"vertically"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/GridLayout.java#L183-L191 |
29,275 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/GridLayout.java | GridLayout.createHorizontallyEndAlignedLayoutData | public static LayoutData createHorizontallyEndAlignedLayoutData(int horizontalSpan) {
return createLayoutData(
Alignment.END,
Alignment.CENTER,
true,
false,
horizontalSpan,
1);
} | java | public static LayoutData createHorizontallyEndAlignedLayoutData(int horizontalSpan) {
return createLayoutData(
Alignment.END,
Alignment.CENTER,
true,
false,
horizontalSpan,
1);
} | [
"public",
"static",
"LayoutData",
"createHorizontallyEndAlignedLayoutData",
"(",
"int",
"horizontalSpan",
")",
"{",
"return",
"createLayoutData",
"(",
"Alignment",
".",
"END",
",",
"Alignment",
".",
"CENTER",
",",
"true",
",",
"false",
",",
"horizontalSpan",
",",
"1",
")",
";",
"}"
] | This is a shortcut method that will create a grid layout data object that will expand its cell as much as is can
vertically and make the component occupy the whole area vertically and center it horizontally
@param horizontalSpan How many cells to span vertically
@return Layout data object with the specified span and vertically expanding as much as it can | [
"This",
"is",
"a",
"shortcut",
"method",
"that",
"will",
"create",
"a",
"grid",
"layout",
"data",
"object",
"that",
"will",
"expand",
"its",
"cell",
"as",
"much",
"as",
"is",
"can",
"vertically",
"and",
"make",
"the",
"component",
"occupy",
"the",
"whole",
"area",
"vertically",
"and",
"center",
"it",
"horizontally"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/GridLayout.java#L199-L207 |
29,276 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/CheckBox.java | CheckBox.setChecked | public synchronized CheckBox setChecked(final boolean checked) {
this.checked = checked;
runOnGUIThreadIfExistsOtherwiseRunDirect(new Runnable() {
@Override
public void run() {
for(Listener listener : listeners) {
listener.onStatusChanged(checked);
}
}
});
invalidate();
return this;
} | java | public synchronized CheckBox setChecked(final boolean checked) {
this.checked = checked;
runOnGUIThreadIfExistsOtherwiseRunDirect(new Runnable() {
@Override
public void run() {
for(Listener listener : listeners) {
listener.onStatusChanged(checked);
}
}
});
invalidate();
return this;
} | [
"public",
"synchronized",
"CheckBox",
"setChecked",
"(",
"final",
"boolean",
"checked",
")",
"{",
"this",
".",
"checked",
"=",
"checked",
";",
"runOnGUIThreadIfExistsOtherwiseRunDirect",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"for",
"(",
"Listener",
"listener",
":",
"listeners",
")",
"{",
"listener",
".",
"onStatusChanged",
"(",
"checked",
")",
";",
"}",
"}",
"}",
")",
";",
"invalidate",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Programmatically updated the check box to a particular checked state
@param checked If {@code true}, the check box will be set to toggled on, otherwise {@code false}
@return Itself | [
"Programmatically",
"updated",
"the",
"check",
"box",
"to",
"a",
"particular",
"checked",
"state"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/CheckBox.java#L83-L95 |
29,277 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/CheckBox.java | CheckBox.setLabel | public synchronized CheckBox setLabel(String label) {
if(label == null) {
throw new IllegalArgumentException("Cannot set CheckBox label to null");
}
this.label = label;
invalidate();
return this;
} | java | public synchronized CheckBox setLabel(String label) {
if(label == null) {
throw new IllegalArgumentException("Cannot set CheckBox label to null");
}
this.label = label;
invalidate();
return this;
} | [
"public",
"synchronized",
"CheckBox",
"setLabel",
"(",
"String",
"label",
")",
"{",
"if",
"(",
"label",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cannot set CheckBox label to null\"",
")",
";",
"}",
"this",
".",
"label",
"=",
"label",
";",
"invalidate",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Updates the label of the checkbox
@param label New label to assign to the check box
@return Itself | [
"Updates",
"the",
"label",
"of",
"the",
"checkbox"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/CheckBox.java#L120-L127 |
29,278 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/CheckBox.java | CheckBox.addListener | public CheckBox addListener(Listener listener) {
if(listener != null && !listeners.contains(listener)) {
listeners.add(listener);
}
return this;
} | java | public CheckBox addListener(Listener listener) {
if(listener != null && !listeners.contains(listener)) {
listeners.add(listener);
}
return this;
} | [
"public",
"CheckBox",
"addListener",
"(",
"Listener",
"listener",
")",
"{",
"if",
"(",
"listener",
"!=",
"null",
"&&",
"!",
"listeners",
".",
"contains",
"(",
"listener",
")",
")",
"{",
"listeners",
".",
"add",
"(",
"listener",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Adds a listener to this check box so that it will be notificed on certain user actions
@param listener Listener to fire events on
@return Itself | [
"Adds",
"a",
"listener",
"to",
"this",
"check",
"box",
"so",
"that",
"it",
"will",
"be",
"notificed",
"on",
"certain",
"user",
"actions"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/CheckBox.java#L142-L147 |
29,279 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/terminal/swing/GraphicalTerminalImplementation.java | GraphicalTerminalImplementation.startBlinkTimer | synchronized void startBlinkTimer() {
if(blinkTimer != null) {
// Already on!
return;
}
blinkTimer = new Timer("LanternaTerminalBlinkTimer", true);
blinkTimer.schedule(new TimerTask() {
@Override
public void run() {
blinkOn = !blinkOn;
if(hasBlinkingText) {
repaint();
}
}
}, deviceConfiguration.getBlinkLengthInMilliSeconds(), deviceConfiguration.getBlinkLengthInMilliSeconds());
} | java | synchronized void startBlinkTimer() {
if(blinkTimer != null) {
// Already on!
return;
}
blinkTimer = new Timer("LanternaTerminalBlinkTimer", true);
blinkTimer.schedule(new TimerTask() {
@Override
public void run() {
blinkOn = !blinkOn;
if(hasBlinkingText) {
repaint();
}
}
}, deviceConfiguration.getBlinkLengthInMilliSeconds(), deviceConfiguration.getBlinkLengthInMilliSeconds());
} | [
"synchronized",
"void",
"startBlinkTimer",
"(",
")",
"{",
"if",
"(",
"blinkTimer",
"!=",
"null",
")",
"{",
"// Already on!",
"return",
";",
"}",
"blinkTimer",
"=",
"new",
"Timer",
"(",
"\"LanternaTerminalBlinkTimer\"",
",",
"true",
")",
";",
"blinkTimer",
".",
"schedule",
"(",
"new",
"TimerTask",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"blinkOn",
"=",
"!",
"blinkOn",
";",
"if",
"(",
"hasBlinkingText",
")",
"{",
"repaint",
"(",
")",
";",
"}",
"}",
"}",
",",
"deviceConfiguration",
".",
"getBlinkLengthInMilliSeconds",
"(",
")",
",",
"deviceConfiguration",
".",
"getBlinkLengthInMilliSeconds",
"(",
")",
")",
";",
"}"
] | Start the timer that triggers blinking | [
"Start",
"the",
"timer",
"that",
"triggers",
"blinking"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/terminal/swing/GraphicalTerminalImplementation.java#L202-L217 |
29,280 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/terminal/swing/GraphicalTerminalImplementation.java | GraphicalTerminalImplementation.getPreferredSize | synchronized Dimension getPreferredSize() {
return new Dimension(getFontWidth() * virtualTerminal.getTerminalSize().getColumns(),
getFontHeight() * virtualTerminal.getTerminalSize().getRows());
} | java | synchronized Dimension getPreferredSize() {
return new Dimension(getFontWidth() * virtualTerminal.getTerminalSize().getColumns(),
getFontHeight() * virtualTerminal.getTerminalSize().getRows());
} | [
"synchronized",
"Dimension",
"getPreferredSize",
"(",
")",
"{",
"return",
"new",
"Dimension",
"(",
"getFontWidth",
"(",
")",
"*",
"virtualTerminal",
".",
"getTerminalSize",
"(",
")",
".",
"getColumns",
"(",
")",
",",
"getFontHeight",
"(",
")",
"*",
"virtualTerminal",
".",
"getTerminalSize",
"(",
")",
".",
"getRows",
"(",
")",
")",
";",
"}"
] | Calculates the preferred size of this terminal
@return Preferred size of this terminal | [
"Calculates",
"the",
"preferred",
"size",
"of",
"this",
"terminal"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/terminal/swing/GraphicalTerminalImplementation.java#L238-L241 |
29,281 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/terminal/swing/GraphicalTerminalImplementation.java | GraphicalTerminalImplementation.clearBackBuffer | private void clearBackBuffer() {
// Manually clear the backbuffer
if(backbuffer != null) {
Graphics2D graphics = backbuffer.createGraphics();
Color backgroundColor = colorConfiguration.toAWTColor(TextColor.ANSI.DEFAULT, false, false);
graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.dispose();
}
} | java | private void clearBackBuffer() {
// Manually clear the backbuffer
if(backbuffer != null) {
Graphics2D graphics = backbuffer.createGraphics();
Color backgroundColor = colorConfiguration.toAWTColor(TextColor.ANSI.DEFAULT, false, false);
graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.dispose();
}
} | [
"private",
"void",
"clearBackBuffer",
"(",
")",
"{",
"// Manually clear the backbuffer",
"if",
"(",
"backbuffer",
"!=",
"null",
")",
"{",
"Graphics2D",
"graphics",
"=",
"backbuffer",
".",
"createGraphics",
"(",
")",
";",
"Color",
"backgroundColor",
"=",
"colorConfiguration",
".",
"toAWTColor",
"(",
"TextColor",
".",
"ANSI",
".",
"DEFAULT",
",",
"false",
",",
"false",
")",
";",
"graphics",
".",
"setColor",
"(",
"backgroundColor",
")",
";",
"graphics",
".",
"fillRect",
"(",
"0",
",",
"0",
",",
"getWidth",
"(",
")",
",",
"getHeight",
"(",
")",
")",
";",
"graphics",
".",
"dispose",
"(",
")",
";",
"}",
"}"
] | Clears out the back buffer and the resets the visual state so next paint operation will do a full repaint of
everything | [
"Clears",
"out",
"the",
"back",
"buffer",
"and",
"the",
"resets",
"the",
"visual",
"state",
"so",
"next",
"paint",
"operation",
"will",
"do",
"a",
"full",
"repaint",
"of",
"everything"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/terminal/swing/GraphicalTerminalImplementation.java#L677-L686 |
29,282 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/graphics/SimpleTheme.java | SimpleTheme.makeTheme | public static SimpleTheme makeTheme(
boolean activeIsBold,
TextColor baseForeground,
TextColor baseBackground,
TextColor editableForeground,
TextColor editableBackground,
TextColor selectedForeground,
TextColor selectedBackground,
TextColor guiBackground) {
SGR[] activeStyle = activeIsBold ? new SGR[]{SGR.BOLD} : new SGR[0];
SimpleTheme theme = new SimpleTheme(baseForeground, baseBackground);
theme.getDefaultDefinition().setSelected(baseBackground, baseForeground, activeStyle);
theme.getDefaultDefinition().setActive(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(AbstractBorder.class, baseForeground, baseBackground)
.setSelected(baseForeground, baseBackground, activeStyle);
theme.addOverride(AbstractListBox.class, baseForeground, baseBackground)
.setSelected(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(Button.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle)
.setSelected(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(CheckBox.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle)
.setPreLight(selectedForeground, selectedBackground, activeStyle)
.setSelected(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(CheckBoxList.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(ComboBox.class, baseForeground, baseBackground)
.setActive(editableForeground, editableBackground, activeStyle)
.setPreLight(editableForeground, editableBackground);
theme.addOverride(DefaultWindowDecorationRenderer.class, baseForeground, baseBackground)
.setActive(baseForeground, baseBackground, activeStyle);
theme.addOverride(GUIBackdrop.class, baseForeground, guiBackground);
theme.addOverride(RadioBoxList.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(Table.class, baseForeground, baseBackground)
.setActive(editableForeground, editableBackground, activeStyle)
.setSelected(baseForeground, baseBackground);
theme.addOverride(TextBox.class, editableForeground, editableBackground)
.setActive(editableForeground, editableBackground, activeStyle)
.setSelected(editableForeground, editableBackground, activeStyle);
theme.setWindowPostRenderer(new WindowShadowRenderer());
return theme;
} | java | public static SimpleTheme makeTheme(
boolean activeIsBold,
TextColor baseForeground,
TextColor baseBackground,
TextColor editableForeground,
TextColor editableBackground,
TextColor selectedForeground,
TextColor selectedBackground,
TextColor guiBackground) {
SGR[] activeStyle = activeIsBold ? new SGR[]{SGR.BOLD} : new SGR[0];
SimpleTheme theme = new SimpleTheme(baseForeground, baseBackground);
theme.getDefaultDefinition().setSelected(baseBackground, baseForeground, activeStyle);
theme.getDefaultDefinition().setActive(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(AbstractBorder.class, baseForeground, baseBackground)
.setSelected(baseForeground, baseBackground, activeStyle);
theme.addOverride(AbstractListBox.class, baseForeground, baseBackground)
.setSelected(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(Button.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle)
.setSelected(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(CheckBox.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle)
.setPreLight(selectedForeground, selectedBackground, activeStyle)
.setSelected(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(CheckBoxList.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(ComboBox.class, baseForeground, baseBackground)
.setActive(editableForeground, editableBackground, activeStyle)
.setPreLight(editableForeground, editableBackground);
theme.addOverride(DefaultWindowDecorationRenderer.class, baseForeground, baseBackground)
.setActive(baseForeground, baseBackground, activeStyle);
theme.addOverride(GUIBackdrop.class, baseForeground, guiBackground);
theme.addOverride(RadioBoxList.class, baseForeground, baseBackground)
.setActive(selectedForeground, selectedBackground, activeStyle);
theme.addOverride(Table.class, baseForeground, baseBackground)
.setActive(editableForeground, editableBackground, activeStyle)
.setSelected(baseForeground, baseBackground);
theme.addOverride(TextBox.class, editableForeground, editableBackground)
.setActive(editableForeground, editableBackground, activeStyle)
.setSelected(editableForeground, editableBackground, activeStyle);
theme.setWindowPostRenderer(new WindowShadowRenderer());
return theme;
} | [
"public",
"static",
"SimpleTheme",
"makeTheme",
"(",
"boolean",
"activeIsBold",
",",
"TextColor",
"baseForeground",
",",
"TextColor",
"baseBackground",
",",
"TextColor",
"editableForeground",
",",
"TextColor",
"editableBackground",
",",
"TextColor",
"selectedForeground",
",",
"TextColor",
"selectedBackground",
",",
"TextColor",
"guiBackground",
")",
"{",
"SGR",
"[",
"]",
"activeStyle",
"=",
"activeIsBold",
"?",
"new",
"SGR",
"[",
"]",
"{",
"SGR",
".",
"BOLD",
"}",
":",
"new",
"SGR",
"[",
"0",
"]",
";",
"SimpleTheme",
"theme",
"=",
"new",
"SimpleTheme",
"(",
"baseForeground",
",",
"baseBackground",
")",
";",
"theme",
".",
"getDefaultDefinition",
"(",
")",
".",
"setSelected",
"(",
"baseBackground",
",",
"baseForeground",
",",
"activeStyle",
")",
";",
"theme",
".",
"getDefaultDefinition",
"(",
")",
".",
"setActive",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"AbstractBorder",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setSelected",
"(",
"baseForeground",
",",
"baseBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"AbstractListBox",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setSelected",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"Button",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setActive",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
".",
"setSelected",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"CheckBox",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setActive",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
".",
"setPreLight",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
".",
"setSelected",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"CheckBoxList",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setActive",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"ComboBox",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setActive",
"(",
"editableForeground",
",",
"editableBackground",
",",
"activeStyle",
")",
".",
"setPreLight",
"(",
"editableForeground",
",",
"editableBackground",
")",
";",
"theme",
".",
"addOverride",
"(",
"DefaultWindowDecorationRenderer",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setActive",
"(",
"baseForeground",
",",
"baseBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"GUIBackdrop",
".",
"class",
",",
"baseForeground",
",",
"guiBackground",
")",
";",
"theme",
".",
"addOverride",
"(",
"RadioBoxList",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setActive",
"(",
"selectedForeground",
",",
"selectedBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"addOverride",
"(",
"Table",
".",
"class",
",",
"baseForeground",
",",
"baseBackground",
")",
".",
"setActive",
"(",
"editableForeground",
",",
"editableBackground",
",",
"activeStyle",
")",
".",
"setSelected",
"(",
"baseForeground",
",",
"baseBackground",
")",
";",
"theme",
".",
"addOverride",
"(",
"TextBox",
".",
"class",
",",
"editableForeground",
",",
"editableBackground",
")",
".",
"setActive",
"(",
"editableForeground",
",",
"editableBackground",
",",
"activeStyle",
")",
".",
"setSelected",
"(",
"editableForeground",
",",
"editableBackground",
",",
"activeStyle",
")",
";",
"theme",
".",
"setWindowPostRenderer",
"(",
"new",
"WindowShadowRenderer",
"(",
")",
")",
";",
"return",
"theme",
";",
"}"
] | Helper method that will quickly setup a new theme with some sensible component overrides.
@param activeIsBold Should focused components also use bold SGR style?
@param baseForeground The base foreground color of the theme
@param baseBackground The base background color of the theme
@param editableForeground Foreground color for editable components, or editable areas of components
@param editableBackground Background color for editable components, or editable areas of components
@param selectedForeground Foreground color for the selection marker when a component has multiple selection states
@param selectedBackground Background color for the selection marker when a component has multiple selection states
@param guiBackground Background color of the GUI, if this theme is assigned to the {@link TextGUI}
@return Assembled {@link SimpleTheme} using the parameters from above | [
"Helper",
"method",
"that",
"will",
"quickly",
"setup",
"a",
"new",
"theme",
"with",
"some",
"sensible",
"component",
"overrides",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/graphics/SimpleTheme.java#L49-L96 |
29,283 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/graphics/SimpleTheme.java | SimpleTheme.addOverride | public synchronized Definition addOverride(Class<?> clazz, TextColor foreground, TextColor background, SGR... styles) {
Definition definition = new Definition(new Style(foreground, background, styles));
overrideDefinitions.put(clazz, definition);
return definition;
} | java | public synchronized Definition addOverride(Class<?> clazz, TextColor foreground, TextColor background, SGR... styles) {
Definition definition = new Definition(new Style(foreground, background, styles));
overrideDefinitions.put(clazz, definition);
return definition;
} | [
"public",
"synchronized",
"Definition",
"addOverride",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"TextColor",
"foreground",
",",
"TextColor",
"background",
",",
"SGR",
"...",
"styles",
")",
"{",
"Definition",
"definition",
"=",
"new",
"Definition",
"(",
"new",
"Style",
"(",
"foreground",
",",
"background",
",",
"styles",
")",
")",
";",
"overrideDefinitions",
".",
"put",
"(",
"clazz",
",",
"definition",
")",
";",
"return",
"definition",
";",
"}"
] | Adds an override for a particular class, or overwrites a previously defined override.
@param clazz Class to override the theme for
@param foreground Color to use as the foreground color for this override style
@param background Color to use as the background color for this override style
@param styles SGR styles to apply for this override
@return The newly created {@link Definition} that corresponds to this override. | [
"Adds",
"an",
"override",
"for",
"a",
"particular",
"class",
"or",
"overwrites",
"a",
"previously",
"defined",
"override",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/graphics/SimpleTheme.java#L138-L142 |
29,284 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java | TableModel.getRows | public synchronized List<List<V>> getRows() {
List<List<V>> copy = new ArrayList<List<V>>();
for(List<V> row: rows) {
copy.add(new ArrayList<V>(row));
}
return copy;
} | java | public synchronized List<List<V>> getRows() {
List<List<V>> copy = new ArrayList<List<V>>();
for(List<V> row: rows) {
copy.add(new ArrayList<V>(row));
}
return copy;
} | [
"public",
"synchronized",
"List",
"<",
"List",
"<",
"V",
">",
">",
"getRows",
"(",
")",
"{",
"List",
"<",
"List",
"<",
"V",
">>",
"copy",
"=",
"new",
"ArrayList",
"<",
"List",
"<",
"V",
">",
">",
"(",
")",
";",
"for",
"(",
"List",
"<",
"V",
">",
"row",
":",
"rows",
")",
"{",
"copy",
".",
"add",
"(",
"new",
"ArrayList",
"<",
"V",
">",
"(",
"row",
")",
")",
";",
"}",
"return",
"copy",
";",
"}"
] | Returns all rows in the model as a list of lists containing the data as elements
@return All rows in the model as a list of lists containing the data as elements | [
"Returns",
"all",
"rows",
"in",
"the",
"model",
"as",
"a",
"list",
"of",
"lists",
"containing",
"the",
"data",
"as",
"elements"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java#L111-L117 |
29,285 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java | TableModel.insertRow | public synchronized TableModel<V> insertRow(int index, Collection<V> values) {
ArrayList<V> list = new ArrayList<V>(values);
rows.add(index, list);
for(Listener<V> listener: listeners) {
listener.onRowAdded(this, index);
}
return this;
} | java | public synchronized TableModel<V> insertRow(int index, Collection<V> values) {
ArrayList<V> list = new ArrayList<V>(values);
rows.add(index, list);
for(Listener<V> listener: listeners) {
listener.onRowAdded(this, index);
}
return this;
} | [
"public",
"synchronized",
"TableModel",
"<",
"V",
">",
"insertRow",
"(",
"int",
"index",
",",
"Collection",
"<",
"V",
">",
"values",
")",
"{",
"ArrayList",
"<",
"V",
">",
"list",
"=",
"new",
"ArrayList",
"<",
"V",
">",
"(",
"values",
")",
";",
"rows",
".",
"add",
"(",
"index",
",",
"list",
")",
";",
"for",
"(",
"Listener",
"<",
"V",
">",
"listener",
":",
"listeners",
")",
"{",
"listener",
".",
"onRowAdded",
"(",
"this",
",",
"index",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Inserts a new row to the table model at a particular index
@param index Index the new row should have, 0 means the first row and <i>row count</i> will append the row at the
end
@param values Data to associate with the new row, mapped column by column in order
@return Itself | [
"Inserts",
"a",
"new",
"row",
"to",
"the",
"table",
"model",
"at",
"a",
"particular",
"index"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java#L163-L170 |
29,286 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java | TableModel.removeRow | public synchronized TableModel<V> removeRow(int index) {
List<V> removedRow = rows.remove(index);
for(Listener<V> listener: listeners) {
listener.onRowRemoved(this, index, removedRow);
}
return this;
} | java | public synchronized TableModel<V> removeRow(int index) {
List<V> removedRow = rows.remove(index);
for(Listener<V> listener: listeners) {
listener.onRowRemoved(this, index, removedRow);
}
return this;
} | [
"public",
"synchronized",
"TableModel",
"<",
"V",
">",
"removeRow",
"(",
"int",
"index",
")",
"{",
"List",
"<",
"V",
">",
"removedRow",
"=",
"rows",
".",
"remove",
"(",
"index",
")",
";",
"for",
"(",
"Listener",
"<",
"V",
">",
"listener",
":",
"listeners",
")",
"{",
"listener",
".",
"onRowRemoved",
"(",
"this",
",",
"index",
",",
"removedRow",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Removes a row at a particular index from the table model
@param index Index of the row to remove
@return Itself | [
"Removes",
"a",
"row",
"at",
"a",
"particular",
"index",
"from",
"the",
"table",
"model"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java#L177-L183 |
29,287 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java | TableModel.setColumnLabel | public synchronized TableModel<V> setColumnLabel(int index, String newLabel) {
columns.set(index, newLabel);
return this;
} | java | public synchronized TableModel<V> setColumnLabel(int index, String newLabel) {
columns.set(index, newLabel);
return this;
} | [
"public",
"synchronized",
"TableModel",
"<",
"V",
">",
"setColumnLabel",
"(",
"int",
"index",
",",
"String",
"newLabel",
")",
"{",
"columns",
".",
"set",
"(",
"index",
",",
"newLabel",
")",
";",
"return",
"this",
";",
"}"
] | Updates the label of a column header
@param index Index of the column to update the header label for
@param newLabel New label to assign to the column header
@return Itself | [
"Updates",
"the",
"label",
"of",
"a",
"column",
"header"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java#L211-L214 |
29,288 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java | TableModel.removeColumn | public synchronized TableModel<V> removeColumn(int index) {
String removedColumnHeader = columns.remove(index);
List<V> removedColumn = new ArrayList<V>();
for(List<V> row : rows) {
removedColumn.add(row.remove(index));
}
for(Listener<V> listener: listeners) {
listener.onColumnRemoved(this, index, removedColumnHeader, removedColumn);
}
return this;
} | java | public synchronized TableModel<V> removeColumn(int index) {
String removedColumnHeader = columns.remove(index);
List<V> removedColumn = new ArrayList<V>();
for(List<V> row : rows) {
removedColumn.add(row.remove(index));
}
for(Listener<V> listener: listeners) {
listener.onColumnRemoved(this, index, removedColumnHeader, removedColumn);
}
return this;
} | [
"public",
"synchronized",
"TableModel",
"<",
"V",
">",
"removeColumn",
"(",
"int",
"index",
")",
"{",
"String",
"removedColumnHeader",
"=",
"columns",
".",
"remove",
"(",
"index",
")",
";",
"List",
"<",
"V",
">",
"removedColumn",
"=",
"new",
"ArrayList",
"<",
"V",
">",
"(",
")",
";",
"for",
"(",
"List",
"<",
"V",
">",
"row",
":",
"rows",
")",
"{",
"removedColumn",
".",
"add",
"(",
"row",
".",
"remove",
"(",
"index",
")",
")",
";",
"}",
"for",
"(",
"Listener",
"<",
"V",
">",
"listener",
":",
"listeners",
")",
"{",
"listener",
".",
"onColumnRemoved",
"(",
"this",
",",
"index",
",",
"removedColumnHeader",
",",
"removedColumn",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Removes a column from the table model
@param index Index of the column to remove
@return Itself | [
"Removes",
"a",
"column",
"from",
"the",
"table",
"model"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/table/TableModel.java#L266-L276 |
29,289 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/terminal/swing/TerminalEmulatorPalette.java | TerminalEmulatorPalette.get | public Color get(TextColor.ANSI color, boolean isForeground, boolean useBrightTones) {
if(useBrightTones) {
switch(color) {
case BLACK:
return brightBlack;
case BLUE:
return brightBlue;
case CYAN:
return brightCyan;
case DEFAULT:
return isForeground ? defaultBrightColor : defaultBackgroundColor;
case GREEN:
return brightGreen;
case MAGENTA:
return brightMagenta;
case RED:
return brightRed;
case WHITE:
return brightWhite;
case YELLOW:
return brightYellow;
}
}
else {
switch(color) {
case BLACK:
return normalBlack;
case BLUE:
return normalBlue;
case CYAN:
return normalCyan;
case DEFAULT:
return isForeground ? defaultColor : defaultBackgroundColor;
case GREEN:
return normalGreen;
case MAGENTA:
return normalMagenta;
case RED:
return normalRed;
case WHITE:
return normalWhite;
case YELLOW:
return normalYellow;
}
}
throw new IllegalArgumentException("Unknown text color " + color);
} | java | public Color get(TextColor.ANSI color, boolean isForeground, boolean useBrightTones) {
if(useBrightTones) {
switch(color) {
case BLACK:
return brightBlack;
case BLUE:
return brightBlue;
case CYAN:
return brightCyan;
case DEFAULT:
return isForeground ? defaultBrightColor : defaultBackgroundColor;
case GREEN:
return brightGreen;
case MAGENTA:
return brightMagenta;
case RED:
return brightRed;
case WHITE:
return brightWhite;
case YELLOW:
return brightYellow;
}
}
else {
switch(color) {
case BLACK:
return normalBlack;
case BLUE:
return normalBlue;
case CYAN:
return normalCyan;
case DEFAULT:
return isForeground ? defaultColor : defaultBackgroundColor;
case GREEN:
return normalGreen;
case MAGENTA:
return normalMagenta;
case RED:
return normalRed;
case WHITE:
return normalWhite;
case YELLOW:
return normalYellow;
}
}
throw new IllegalArgumentException("Unknown text color " + color);
} | [
"public",
"Color",
"get",
"(",
"TextColor",
".",
"ANSI",
"color",
",",
"boolean",
"isForeground",
",",
"boolean",
"useBrightTones",
")",
"{",
"if",
"(",
"useBrightTones",
")",
"{",
"switch",
"(",
"color",
")",
"{",
"case",
"BLACK",
":",
"return",
"brightBlack",
";",
"case",
"BLUE",
":",
"return",
"brightBlue",
";",
"case",
"CYAN",
":",
"return",
"brightCyan",
";",
"case",
"DEFAULT",
":",
"return",
"isForeground",
"?",
"defaultBrightColor",
":",
"defaultBackgroundColor",
";",
"case",
"GREEN",
":",
"return",
"brightGreen",
";",
"case",
"MAGENTA",
":",
"return",
"brightMagenta",
";",
"case",
"RED",
":",
"return",
"brightRed",
";",
"case",
"WHITE",
":",
"return",
"brightWhite",
";",
"case",
"YELLOW",
":",
"return",
"brightYellow",
";",
"}",
"}",
"else",
"{",
"switch",
"(",
"color",
")",
"{",
"case",
"BLACK",
":",
"return",
"normalBlack",
";",
"case",
"BLUE",
":",
"return",
"normalBlue",
";",
"case",
"CYAN",
":",
"return",
"normalCyan",
";",
"case",
"DEFAULT",
":",
"return",
"isForeground",
"?",
"defaultColor",
":",
"defaultBackgroundColor",
";",
"case",
"GREEN",
":",
"return",
"normalGreen",
";",
"case",
"MAGENTA",
":",
"return",
"normalMagenta",
";",
"case",
"RED",
":",
"return",
"normalRed",
";",
"case",
"WHITE",
":",
"return",
"normalWhite",
";",
"case",
"YELLOW",
":",
"return",
"normalYellow",
";",
"}",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown text color \"",
"+",
"color",
")",
";",
"}"
] | Returns the AWT color from this palette given an ANSI color and two hints for if we are looking for a background
color and if we want to use the bright version.
@param color Which ANSI color we want to extract
@param isForeground Is this color we extract going to be used as a background color?
@param useBrightTones If true, we should return the bright version of the color
@return AWT color extracted from this palette for the input parameters | [
"Returns",
"the",
"AWT",
"color",
"from",
"this",
"palette",
"given",
"an",
"ANSI",
"color",
"and",
"two",
"hints",
"for",
"if",
"we",
"are",
"looking",
"for",
"a",
"background",
"color",
"and",
"if",
"we",
"want",
"to",
"use",
"the",
"bright",
"version",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/terminal/swing/TerminalEmulatorPalette.java#L284-L330 |
29,290 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java | InteractableLookupMap.add | @SuppressWarnings("ConstantConditions")
public synchronized void add(Interactable interactable) {
TerminalPosition topLeft = interactable.toBasePane(TerminalPosition.TOP_LEFT_CORNER);
TerminalSize size = interactable.getSize();
interactables.add(interactable);
int index = interactables.size() - 1;
for(int y = topLeft.getRow(); y < topLeft.getRow() + size.getRows(); y++) {
for(int x = topLeft.getColumn(); x < topLeft.getColumn() + size.getColumns(); x++) {
//Make sure it's not outside the map
if(y >= 0 && y < lookupMap.length &&
x >= 0 && x < lookupMap[y].length) {
lookupMap[y][x] = index;
}
}
}
} | java | @SuppressWarnings("ConstantConditions")
public synchronized void add(Interactable interactable) {
TerminalPosition topLeft = interactable.toBasePane(TerminalPosition.TOP_LEFT_CORNER);
TerminalSize size = interactable.getSize();
interactables.add(interactable);
int index = interactables.size() - 1;
for(int y = topLeft.getRow(); y < topLeft.getRow() + size.getRows(); y++) {
for(int x = topLeft.getColumn(); x < topLeft.getColumn() + size.getColumns(); x++) {
//Make sure it's not outside the map
if(y >= 0 && y < lookupMap.length &&
x >= 0 && x < lookupMap[y].length) {
lookupMap[y][x] = index;
}
}
}
} | [
"@",
"SuppressWarnings",
"(",
"\"ConstantConditions\"",
")",
"public",
"synchronized",
"void",
"add",
"(",
"Interactable",
"interactable",
")",
"{",
"TerminalPosition",
"topLeft",
"=",
"interactable",
".",
"toBasePane",
"(",
"TerminalPosition",
".",
"TOP_LEFT_CORNER",
")",
";",
"TerminalSize",
"size",
"=",
"interactable",
".",
"getSize",
"(",
")",
";",
"interactables",
".",
"add",
"(",
"interactable",
")",
";",
"int",
"index",
"=",
"interactables",
".",
"size",
"(",
")",
"-",
"1",
";",
"for",
"(",
"int",
"y",
"=",
"topLeft",
".",
"getRow",
"(",
")",
";",
"y",
"<",
"topLeft",
".",
"getRow",
"(",
")",
"+",
"size",
".",
"getRows",
"(",
")",
";",
"y",
"++",
")",
"{",
"for",
"(",
"int",
"x",
"=",
"topLeft",
".",
"getColumn",
"(",
")",
";",
"x",
"<",
"topLeft",
".",
"getColumn",
"(",
")",
"+",
"size",
".",
"getColumns",
"(",
")",
";",
"x",
"++",
")",
"{",
"//Make sure it's not outside the map",
"if",
"(",
"y",
">=",
"0",
"&&",
"y",
"<",
"lookupMap",
".",
"length",
"&&",
"x",
">=",
"0",
"&&",
"x",
"<",
"lookupMap",
"[",
"y",
"]",
".",
"length",
")",
"{",
"lookupMap",
"[",
"y",
"]",
"[",
"x",
"]",
"=",
"index",
";",
"}",
"}",
"}",
"}"
] | Adds an interactable component to the lookup map
@param interactable Interactable to add to the lookup map | [
"Adds",
"an",
"interactable",
"component",
"to",
"the",
"lookup",
"map"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java#L59-L74 |
29,291 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java | InteractableLookupMap.getInteractableAt | public synchronized Interactable getInteractableAt(TerminalPosition position) {
if (position.getRow() < 0 || position.getColumn() < 0) {
return null;
}
if(position.getRow() >= lookupMap.length) {
return null;
}
else if(position.getColumn() >= lookupMap[0].length) {
return null;
}
else if(lookupMap[position.getRow()][position.getColumn()] == -1) {
return null;
}
return interactables.get(lookupMap[position.getRow()][position.getColumn()]);
} | java | public synchronized Interactable getInteractableAt(TerminalPosition position) {
if (position.getRow() < 0 || position.getColumn() < 0) {
return null;
}
if(position.getRow() >= lookupMap.length) {
return null;
}
else if(position.getColumn() >= lookupMap[0].length) {
return null;
}
else if(lookupMap[position.getRow()][position.getColumn()] == -1) {
return null;
}
return interactables.get(lookupMap[position.getRow()][position.getColumn()]);
} | [
"public",
"synchronized",
"Interactable",
"getInteractableAt",
"(",
"TerminalPosition",
"position",
")",
"{",
"if",
"(",
"position",
".",
"getRow",
"(",
")",
"<",
"0",
"||",
"position",
".",
"getColumn",
"(",
")",
"<",
"0",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"position",
".",
"getRow",
"(",
")",
">=",
"lookupMap",
".",
"length",
")",
"{",
"return",
"null",
";",
"}",
"else",
"if",
"(",
"position",
".",
"getColumn",
"(",
")",
">=",
"lookupMap",
"[",
"0",
"]",
".",
"length",
")",
"{",
"return",
"null",
";",
"}",
"else",
"if",
"(",
"lookupMap",
"[",
"position",
".",
"getRow",
"(",
")",
"]",
"[",
"position",
".",
"getColumn",
"(",
")",
"]",
"==",
"-",
"1",
")",
"{",
"return",
"null",
";",
"}",
"return",
"interactables",
".",
"get",
"(",
"lookupMap",
"[",
"position",
".",
"getRow",
"(",
")",
"]",
"[",
"position",
".",
"getColumn",
"(",
")",
"]",
")",
";",
"}"
] | Looks up what interactable component is as a particular location in the map
@param position Position to look up
@return The {@code Interactable} component at the specified location or {@code null} if there's nothing there | [
"Looks",
"up",
"what",
"interactable",
"component",
"is",
"as",
"a",
"particular",
"location",
"in",
"the",
"map"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/InteractableLookupMap.java#L81-L95 |
29,292 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/dialogs/ListSelectDialogBuilder.java | ListSelectDialogBuilder.addListItems | public ListSelectDialogBuilder<T> addListItems(T... items) {
this.content.addAll(Arrays.asList(items));
return this;
} | java | public ListSelectDialogBuilder<T> addListItems(T... items) {
this.content.addAll(Arrays.asList(items));
return this;
} | [
"public",
"ListSelectDialogBuilder",
"<",
"T",
">",
"addListItems",
"(",
"T",
"...",
"items",
")",
"{",
"this",
".",
"content",
".",
"addAll",
"(",
"Arrays",
".",
"asList",
"(",
"items",
")",
")",
";",
"return",
"this",
";",
"}"
] | Adds a list of items to the list box at the end, in the order they are passed in
@param items Items to add to the list box
@return Itself | [
"Adds",
"a",
"list",
"of",
"items",
"to",
"the",
"list",
"box",
"at",
"the",
"end",
"in",
"the",
"order",
"they",
"are",
"passed",
"in"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/dialogs/ListSelectDialogBuilder.java#L115-L118 |
29,293 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/CheckBoxList.java | CheckBoxList.addItem | public synchronized CheckBoxList<V> addItem(V object, boolean checkedState) {
itemStatus.add(checkedState);
return super.addItem(object);
} | java | public synchronized CheckBoxList<V> addItem(V object, boolean checkedState) {
itemStatus.add(checkedState);
return super.addItem(object);
} | [
"public",
"synchronized",
"CheckBoxList",
"<",
"V",
">",
"addItem",
"(",
"V",
"object",
",",
"boolean",
"checkedState",
")",
"{",
"itemStatus",
".",
"add",
"(",
"checkedState",
")",
";",
"return",
"super",
".",
"addItem",
"(",
"object",
")",
";",
"}"
] | Adds an item to the checkbox list with an explicit checked status
@param object Object to add to the list
@param checkedState If <code>true</code>, the new item will be initially checked
@return Itself | [
"Adds",
"an",
"item",
"to",
"the",
"checkbox",
"list",
"with",
"an",
"explicit",
"checked",
"status"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/CheckBoxList.java#L99-L102 |
29,294 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/CheckBoxList.java | CheckBoxList.setChecked | public synchronized CheckBoxList<V> setChecked(V object, boolean checked) {
int index = indexOf(object);
if(index != -1) {
setChecked(index, checked);
}
return self();
} | java | public synchronized CheckBoxList<V> setChecked(V object, boolean checked) {
int index = indexOf(object);
if(index != -1) {
setChecked(index, checked);
}
return self();
} | [
"public",
"synchronized",
"CheckBoxList",
"<",
"V",
">",
"setChecked",
"(",
"V",
"object",
",",
"boolean",
"checked",
")",
"{",
"int",
"index",
"=",
"indexOf",
"(",
"object",
")",
";",
"if",
"(",
"index",
"!=",
"-",
"1",
")",
"{",
"setChecked",
"(",
"index",
",",
"checked",
")",
";",
"}",
"return",
"self",
"(",
")",
";",
"}"
] | Programmatically sets the checked state of an item in the list box
@param object Object to set the checked state of
@param checked If {@code true}, then the item is set to checked, otherwise not
@return Itself | [
"Programmatically",
"sets",
"the",
"checked",
"state",
"of",
"an",
"item",
"in",
"the",
"list",
"box"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/CheckBoxList.java#L138-L144 |
29,295 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/CheckBoxList.java | CheckBoxList.getCheckedItems | public synchronized List<V> getCheckedItems() {
List<V> result = new ArrayList<V>();
for(int i = 0; i < itemStatus.size(); i++) {
if(itemStatus.get(i)) {
result.add(getItemAt(i));
}
}
return result;
} | java | public synchronized List<V> getCheckedItems() {
List<V> result = new ArrayList<V>();
for(int i = 0; i < itemStatus.size(); i++) {
if(itemStatus.get(i)) {
result.add(getItemAt(i));
}
}
return result;
} | [
"public",
"synchronized",
"List",
"<",
"V",
">",
"getCheckedItems",
"(",
")",
"{",
"List",
"<",
"V",
">",
"result",
"=",
"new",
"ArrayList",
"<",
"V",
">",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"itemStatus",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"itemStatus",
".",
"get",
"(",
"i",
")",
")",
"{",
"result",
".",
"add",
"(",
"getItemAt",
"(",
"i",
")",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Returns all the items in the list box that have checked state, as a list
@return List of all items in the list box that has checked state on | [
"Returns",
"all",
"the",
"items",
"in",
"the",
"list",
"box",
"that",
"have",
"checked",
"state",
"as",
"a",
"list"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/CheckBoxList.java#L162-L170 |
29,296 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/input/InputDecoder.java | InputDecoder.addProfile | public void addProfile(KeyDecodingProfile profile) {
for (CharacterPattern pattern : profile.getPatterns()) {
synchronized(bytePatterns) {
//If an equivalent pattern already exists, remove it first
bytePatterns.remove(pattern);
bytePatterns.add(pattern);
}
}
} | java | public void addProfile(KeyDecodingProfile profile) {
for (CharacterPattern pattern : profile.getPatterns()) {
synchronized(bytePatterns) {
//If an equivalent pattern already exists, remove it first
bytePatterns.remove(pattern);
bytePatterns.add(pattern);
}
}
} | [
"public",
"void",
"addProfile",
"(",
"KeyDecodingProfile",
"profile",
")",
"{",
"for",
"(",
"CharacterPattern",
"pattern",
":",
"profile",
".",
"getPatterns",
"(",
")",
")",
"{",
"synchronized",
"(",
"bytePatterns",
")",
"{",
"//If an equivalent pattern already exists, remove it first",
"bytePatterns",
".",
"remove",
"(",
"pattern",
")",
";",
"bytePatterns",
".",
"add",
"(",
"pattern",
")",
";",
"}",
"}",
"}"
] | Adds another key decoding profile to this InputDecoder, which means all patterns from the profile will be used
when decoding input.
@param profile Profile to add | [
"Adds",
"another",
"key",
"decoding",
"profile",
"to",
"this",
"InputDecoder",
"which",
"means",
"all",
"patterns",
"from",
"the",
"profile",
"will",
"be",
"used",
"when",
"decoding",
"input",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/input/InputDecoder.java#L57-L65 |
29,297 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/input/InputDecoder.java | InputDecoder.getNextCharacter | public synchronized KeyStroke getNextCharacter(boolean blockingIO) throws IOException {
KeyStroke bestMatch = null;
int bestLen = 0;
int curLen = 0;
while(true) {
if ( curLen < currentMatching.size() ) {
// (re-)consume characters previously read:
curLen++;
}
else {
// If we already have a bestMatch but a chance for a longer match
// then we poll for the configured number of timeout units:
// It would be much better, if we could just read with a timeout,
// but lacking that, we wait 1/4s units and check for readiness.
if (bestMatch != null) {
int timeout = getTimeoutUnits();
while (timeout > 0 && ! source.ready() ) {
try {
timeout--; Thread.sleep(250);
} catch (InterruptedException e) { timeout = 0; }
}
}
// if input is available, we can just read a char without waiting,
// otherwise, for readInput() with no bestMatch found yet,
// we have to wait blocking for more input:
if ( source.ready() || ( blockingIO && bestMatch == null ) ) {
int readChar = source.read();
if (readChar == -1) {
seenEOF = true;
if(currentMatching.isEmpty()) {
return new KeyStroke(KeyType.EOF);
}
break;
}
currentMatching.add( (char)readChar );
curLen++;
} else { // no more available input at this time.
// already found something:
if (bestMatch != null) {
break; // it's something...
}
// otherwise: no KeyStroke yet
return null;
}
}
List<Character> curSub = currentMatching.subList(0, curLen);
Matching matching = getBestMatch( curSub );
// fullMatch found...
if (matching.fullMatch != null) {
bestMatch = matching.fullMatch;
bestLen = curLen;
if (! matching.partialMatch) {
// that match and no more
break;
} else {
// that match, but maybe more
//noinspection UnnecessaryContinue
continue;
}
}
// No match found yet, but there's still potential...
else if ( matching.partialMatch ) {
//noinspection UnnecessaryContinue
continue;
}
// no longer match possible at this point:
else {
if (bestMatch != null ) {
// there was already a previous full-match, use it:
break;
} else { // invalid input!
// remove the whole fail and re-try finding a KeyStroke...
curSub.clear(); // or just 1 char? currentMatching.remove(0);
curLen = 0;
//noinspection UnnecessaryContinue
continue;
}
}
}
//Did we find anything? Otherwise return null
if(bestMatch == null) {
if(seenEOF) {
currentMatching.clear();
return new KeyStroke(KeyType.EOF);
}
return null;
}
List<Character> bestSub = currentMatching.subList(0, bestLen );
bestSub.clear(); // remove matched characters from input
return bestMatch;
} | java | public synchronized KeyStroke getNextCharacter(boolean blockingIO) throws IOException {
KeyStroke bestMatch = null;
int bestLen = 0;
int curLen = 0;
while(true) {
if ( curLen < currentMatching.size() ) {
// (re-)consume characters previously read:
curLen++;
}
else {
// If we already have a bestMatch but a chance for a longer match
// then we poll for the configured number of timeout units:
// It would be much better, if we could just read with a timeout,
// but lacking that, we wait 1/4s units and check for readiness.
if (bestMatch != null) {
int timeout = getTimeoutUnits();
while (timeout > 0 && ! source.ready() ) {
try {
timeout--; Thread.sleep(250);
} catch (InterruptedException e) { timeout = 0; }
}
}
// if input is available, we can just read a char without waiting,
// otherwise, for readInput() with no bestMatch found yet,
// we have to wait blocking for more input:
if ( source.ready() || ( blockingIO && bestMatch == null ) ) {
int readChar = source.read();
if (readChar == -1) {
seenEOF = true;
if(currentMatching.isEmpty()) {
return new KeyStroke(KeyType.EOF);
}
break;
}
currentMatching.add( (char)readChar );
curLen++;
} else { // no more available input at this time.
// already found something:
if (bestMatch != null) {
break; // it's something...
}
// otherwise: no KeyStroke yet
return null;
}
}
List<Character> curSub = currentMatching.subList(0, curLen);
Matching matching = getBestMatch( curSub );
// fullMatch found...
if (matching.fullMatch != null) {
bestMatch = matching.fullMatch;
bestLen = curLen;
if (! matching.partialMatch) {
// that match and no more
break;
} else {
// that match, but maybe more
//noinspection UnnecessaryContinue
continue;
}
}
// No match found yet, but there's still potential...
else if ( matching.partialMatch ) {
//noinspection UnnecessaryContinue
continue;
}
// no longer match possible at this point:
else {
if (bestMatch != null ) {
// there was already a previous full-match, use it:
break;
} else { // invalid input!
// remove the whole fail and re-try finding a KeyStroke...
curSub.clear(); // or just 1 char? currentMatching.remove(0);
curLen = 0;
//noinspection UnnecessaryContinue
continue;
}
}
}
//Did we find anything? Otherwise return null
if(bestMatch == null) {
if(seenEOF) {
currentMatching.clear();
return new KeyStroke(KeyType.EOF);
}
return null;
}
List<Character> bestSub = currentMatching.subList(0, bestLen );
bestSub.clear(); // remove matched characters from input
return bestMatch;
} | [
"public",
"synchronized",
"KeyStroke",
"getNextCharacter",
"(",
"boolean",
"blockingIO",
")",
"throws",
"IOException",
"{",
"KeyStroke",
"bestMatch",
"=",
"null",
";",
"int",
"bestLen",
"=",
"0",
";",
"int",
"curLen",
"=",
"0",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"curLen",
"<",
"currentMatching",
".",
"size",
"(",
")",
")",
"{",
"// (re-)consume characters previously read:",
"curLen",
"++",
";",
"}",
"else",
"{",
"// If we already have a bestMatch but a chance for a longer match",
"// then we poll for the configured number of timeout units:",
"// It would be much better, if we could just read with a timeout,",
"// but lacking that, we wait 1/4s units and check for readiness.",
"if",
"(",
"bestMatch",
"!=",
"null",
")",
"{",
"int",
"timeout",
"=",
"getTimeoutUnits",
"(",
")",
";",
"while",
"(",
"timeout",
">",
"0",
"&&",
"!",
"source",
".",
"ready",
"(",
")",
")",
"{",
"try",
"{",
"timeout",
"--",
";",
"Thread",
".",
"sleep",
"(",
"250",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"timeout",
"=",
"0",
";",
"}",
"}",
"}",
"// if input is available, we can just read a char without waiting,",
"// otherwise, for readInput() with no bestMatch found yet,",
"// we have to wait blocking for more input:",
"if",
"(",
"source",
".",
"ready",
"(",
")",
"||",
"(",
"blockingIO",
"&&",
"bestMatch",
"==",
"null",
")",
")",
"{",
"int",
"readChar",
"=",
"source",
".",
"read",
"(",
")",
";",
"if",
"(",
"readChar",
"==",
"-",
"1",
")",
"{",
"seenEOF",
"=",
"true",
";",
"if",
"(",
"currentMatching",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"new",
"KeyStroke",
"(",
"KeyType",
".",
"EOF",
")",
";",
"}",
"break",
";",
"}",
"currentMatching",
".",
"add",
"(",
"(",
"char",
")",
"readChar",
")",
";",
"curLen",
"++",
";",
"}",
"else",
"{",
"// no more available input at this time.",
"// already found something:",
"if",
"(",
"bestMatch",
"!=",
"null",
")",
"{",
"break",
";",
"// it's something...",
"}",
"// otherwise: no KeyStroke yet",
"return",
"null",
";",
"}",
"}",
"List",
"<",
"Character",
">",
"curSub",
"=",
"currentMatching",
".",
"subList",
"(",
"0",
",",
"curLen",
")",
";",
"Matching",
"matching",
"=",
"getBestMatch",
"(",
"curSub",
")",
";",
"// fullMatch found...",
"if",
"(",
"matching",
".",
"fullMatch",
"!=",
"null",
")",
"{",
"bestMatch",
"=",
"matching",
".",
"fullMatch",
";",
"bestLen",
"=",
"curLen",
";",
"if",
"(",
"!",
"matching",
".",
"partialMatch",
")",
"{",
"// that match and no more",
"break",
";",
"}",
"else",
"{",
"// that match, but maybe more",
"//noinspection UnnecessaryContinue",
"continue",
";",
"}",
"}",
"// No match found yet, but there's still potential...",
"else",
"if",
"(",
"matching",
".",
"partialMatch",
")",
"{",
"//noinspection UnnecessaryContinue",
"continue",
";",
"}",
"// no longer match possible at this point:",
"else",
"{",
"if",
"(",
"bestMatch",
"!=",
"null",
")",
"{",
"// there was already a previous full-match, use it:",
"break",
";",
"}",
"else",
"{",
"// invalid input!",
"// remove the whole fail and re-try finding a KeyStroke...",
"curSub",
".",
"clear",
"(",
")",
";",
"// or just 1 char? currentMatching.remove(0);",
"curLen",
"=",
"0",
";",
"//noinspection UnnecessaryContinue",
"continue",
";",
"}",
"}",
"}",
"//Did we find anything? Otherwise return null",
"if",
"(",
"bestMatch",
"==",
"null",
")",
"{",
"if",
"(",
"seenEOF",
")",
"{",
"currentMatching",
".",
"clear",
"(",
")",
";",
"return",
"new",
"KeyStroke",
"(",
"KeyType",
".",
"EOF",
")",
";",
"}",
"return",
"null",
";",
"}",
"List",
"<",
"Character",
">",
"bestSub",
"=",
"currentMatching",
".",
"subList",
"(",
"0",
",",
"bestLen",
")",
";",
"bestSub",
".",
"clear",
"(",
")",
";",
"// remove matched characters from input",
"return",
"bestMatch",
";",
"}"
] | Reads and decodes the next key stroke from the input stream
@param blockingIO If set to {@code true}, the call will not return until it has read at least one {@link KeyStroke}
@return Key stroke read from the input stream, or {@code null} if none
@throws IOException If there was an I/O error when reading from the input stream | [
"Reads",
"and",
"decodes",
"the",
"next",
"key",
"stroke",
"from",
"the",
"input",
"stream"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/input/InputDecoder.java#L115-L214 |
29,298 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/dialogs/MessageDialog.java | MessageDialog.showMessageDialog | public static MessageDialogButton showMessageDialog(
WindowBasedTextGUI textGUI,
String title,
String text,
MessageDialogButton... buttons) {
MessageDialogBuilder builder = new MessageDialogBuilder()
.setTitle(title)
.setText(text);
if(buttons.length == 0) {
builder.addButton(MessageDialogButton.OK);
}
for(MessageDialogButton button: buttons) {
builder.addButton(button);
}
return builder.build().showDialog(textGUI);
} | java | public static MessageDialogButton showMessageDialog(
WindowBasedTextGUI textGUI,
String title,
String text,
MessageDialogButton... buttons) {
MessageDialogBuilder builder = new MessageDialogBuilder()
.setTitle(title)
.setText(text);
if(buttons.length == 0) {
builder.addButton(MessageDialogButton.OK);
}
for(MessageDialogButton button: buttons) {
builder.addButton(button);
}
return builder.build().showDialog(textGUI);
} | [
"public",
"static",
"MessageDialogButton",
"showMessageDialog",
"(",
"WindowBasedTextGUI",
"textGUI",
",",
"String",
"title",
",",
"String",
"text",
",",
"MessageDialogButton",
"...",
"buttons",
")",
"{",
"MessageDialogBuilder",
"builder",
"=",
"new",
"MessageDialogBuilder",
"(",
")",
".",
"setTitle",
"(",
"title",
")",
".",
"setText",
"(",
"text",
")",
";",
"if",
"(",
"buttons",
".",
"length",
"==",
"0",
")",
"{",
"builder",
".",
"addButton",
"(",
"MessageDialogButton",
".",
"OK",
")",
";",
"}",
"for",
"(",
"MessageDialogButton",
"button",
":",
"buttons",
")",
"{",
"builder",
".",
"addButton",
"(",
"button",
")",
";",
"}",
"return",
"builder",
".",
"build",
"(",
")",
".",
"showDialog",
"(",
"textGUI",
")",
";",
"}"
] | Shortcut for quickly displaying a message box
@param textGUI The GUI to display the message box on
@param title Title of the message box
@param text Main message of the message box
@param buttons Buttons that the user can confirm the message box with
@return Which button the user selected | [
"Shortcut",
"for",
"quickly",
"displaying",
"a",
"message",
"box"
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/dialogs/MessageDialog.java#L93-L108 |
29,299 | mabe02/lanterna | src/main/java/com/googlecode/lanterna/gui2/Panel.java | Panel.addComponent | public Panel addComponent(int index, Component component) {
if(component == null) {
throw new IllegalArgumentException("Cannot add null component");
}
synchronized(components) {
if(components.contains(component)) {
return this;
}
if(component.getParent() != null) {
component.getParent().removeComponent(component);
}
if (index > components.size()) {
index = components.size();
}
else if (index < 0) {
index = 0;
}
components.add(index, component);
}
component.onAdded(this);
invalidate();
return this;
} | java | public Panel addComponent(int index, Component component) {
if(component == null) {
throw new IllegalArgumentException("Cannot add null component");
}
synchronized(components) {
if(components.contains(component)) {
return this;
}
if(component.getParent() != null) {
component.getParent().removeComponent(component);
}
if (index > components.size()) {
index = components.size();
}
else if (index < 0) {
index = 0;
}
components.add(index, component);
}
component.onAdded(this);
invalidate();
return this;
} | [
"public",
"Panel",
"addComponent",
"(",
"int",
"index",
",",
"Component",
"component",
")",
"{",
"if",
"(",
"component",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cannot add null component\"",
")",
";",
"}",
"synchronized",
"(",
"components",
")",
"{",
"if",
"(",
"components",
".",
"contains",
"(",
"component",
")",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"component",
".",
"getParent",
"(",
")",
"!=",
"null",
")",
"{",
"component",
".",
"getParent",
"(",
")",
".",
"removeComponent",
"(",
"component",
")",
";",
"}",
"if",
"(",
"index",
">",
"components",
".",
"size",
"(",
")",
")",
"{",
"index",
"=",
"components",
".",
"size",
"(",
")",
";",
"}",
"else",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"index",
"=",
"0",
";",
"}",
"components",
".",
"add",
"(",
"index",
",",
"component",
")",
";",
"}",
"component",
".",
"onAdded",
"(",
"this",
")",
";",
"invalidate",
"(",
")",
";",
"return",
"this",
";",
"}"
] | Adds a new child component to the panel. Where within the panel the child will be displayed is up to the layout
manager assigned to this panel. If the component has already been added to another panel, it will first be
removed from that panel before added to this one.
@param component Child component to add to this panel
@param index At what index to add the component among the existing components
@return Itself | [
"Adds",
"a",
"new",
"child",
"component",
"to",
"the",
"panel",
".",
"Where",
"within",
"the",
"panel",
"the",
"child",
"will",
"be",
"displayed",
"is",
"up",
"to",
"the",
"layout",
"manager",
"assigned",
"to",
"this",
"panel",
".",
"If",
"the",
"component",
"has",
"already",
"been",
"added",
"to",
"another",
"panel",
"it",
"will",
"first",
"be",
"removed",
"from",
"that",
"panel",
"before",
"added",
"to",
"this",
"one",
"."
] | 8dfd62206ff46ab10223b2ef2dbb0a2c51850954 | https://github.com/mabe02/lanterna/blob/8dfd62206ff46ab10223b2ef2dbb0a2c51850954/src/main/java/com/googlecode/lanterna/gui2/Panel.java#L80-L102 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.