in src/main/c/h3-java/src/jniapi.c [603:682]
void ConvertLinkedGeoPolygonToManaged(JNIEnv *env,
LinkedGeoPolygon *currentPolygon,
jobject results) {
jclass arrayListClass = (**env).FindClass(env, "java/util/ArrayList");
if (arrayListClass == NULL) {
ThrowOutOfMemoryError(env);
return;
}
jclass latLngClass = (**env).FindClass(env, "com/uber/h3core/util/LatLng");
if (latLngClass == NULL) {
ThrowOutOfMemoryError(env);
return;
}
jmethodID arrayListConstructor =
(**env).GetMethodID(env, arrayListClass, "<init>", "()V");
if (arrayListConstructor == NULL) {
ThrowOutOfMemoryError(env);
return;
}
jmethodID arrayListAdd = (**env).GetMethodID(env, arrayListClass, "add",
"(Ljava/lang/Object;)Z");
if (arrayListAdd == NULL) {
ThrowOutOfMemoryError(env);
return;
}
jmethodID latLngConstructor =
(**env).GetMethodID(env, latLngClass, "<init>", "(DD)V");
if (latLngConstructor == NULL) {
ThrowOutOfMemoryError(env);
return;
}
while (currentPolygon != NULL) {
jobject resultLoops =
(**env).NewObject(env, arrayListClass, arrayListConstructor);
if (resultLoops == NULL) {
return;
}
// Check if the polygon is empty.
// Don't have to do this other times because a loop can be gauranteed
// to have coordinates.
if (resultLoops != NULL && currentPolygon->first != NULL) {
LinkedGeoLoop *currentLoop = currentPolygon->first;
while (currentLoop != NULL) {
jobject resultLoop = (**env).NewObject(env, arrayListClass,
arrayListConstructor);
if (resultLoop == NULL) {
return;
}
LinkedLatLng *coord = currentLoop->first;
while (coord != NULL) {
jobject v =
(**env).NewObject(env, latLngClass, latLngConstructor,
coord->vertex.lat, coord->vertex.lng);
if (v == NULL) {
return;
}
(**env).CallBooleanMethod(env, resultLoop, arrayListAdd, v);
RETURN_ON_EXCEPTION(env);
coord = coord->next;
}
(**env).CallBooleanMethod(env, resultLoops, arrayListAdd,
resultLoop);
RETURN_ON_EXCEPTION(env);
currentLoop = currentLoop->next;
}
(**env).CallBooleanMethod(env, results, arrayListAdd, resultLoops);
RETURN_ON_EXCEPTION(env);
}
currentPolygon = currentPolygon->next;
}
}