update bioProject

This commit is contained in:
yanggang 2019-03-05 16:01:27 +08:00
parent cd615ad58e
commit 076ea0173b
2 changed files with 33 additions and 41 deletions

View File

@ -1,41 +0,0 @@
package cn.piflow.bundle.microorganism.util;
import org.json.JSONArray;
import org.json.JSONObject;
public class BioProject {
public void convertConcrete2KeyVal(JSONObject parent, String key){ //the object having the key is either a JSONObject, a JSONArray, or a concrete value like string or integer
if(parent.opt(key) != null){
Object obj = parent.get(key);
if(obj instanceof JSONArray){
for(int i = 0; i < ((JSONArray)obj).length(); i++){
Object single = ((JSONArray)obj).get(i);
if(isConcrete(single)){
JSONObject tmp = new JSONObject();
tmp.put("content", single);
((JSONArray) obj).put(i, tmp);
}
}
}else if(isConcrete(obj)){ //concrete value
JSONObject tmp = new JSONObject();
tmp.put("content", obj);
parent.put(key, tmp);
}
}
}
public boolean isConcrete(Object obj){ //any other basic format??
if(obj instanceof String || obj instanceof Double || obj instanceof Float || obj instanceof Integer || obj instanceof Long){
return true;
}else {
return false;
}
}
}

View File

@ -0,0 +1,33 @@
package cn.piflow.bundle.microorganism.util
import org.json.{JSONArray, JSONObject}
class BioProject {
def convertConcrete2KeyVal(parent: JSONObject, key: String): Unit = {
//the object having the key is either a JSONObject, a JSONArray, or a concrete value like string or integer
if(parent.opt(key) != null){
val obj= parent.get(key)
if (obj.isInstanceOf[JSONArray]){
for (i<- 0 until(obj.asInstanceOf[JSONArray].length)){
val single = obj.asInstanceOf[JSONArray].get(i)
if(isConcrete(single)){
val tmp = new JSONObject
tmp.put("content", single)
obj.asInstanceOf[JSONArray].put(i, tmp)
}
}
} else if (isConcrete(obj)){
val tmp = new JSONObject
tmp.put("content", obj)
parent.put(key, tmp);
}
}
}
def isConcrete(obj: Object): Boolean = { //any other basic format??
if (obj.isInstanceOf[String] || obj.isInstanceOf[Double] || obj.isInstanceOf[Float] || obj.isInstanceOf[Integer] || obj.isInstanceOf[Long]) true
else false
}
}