I have a json data listing all music scales and their keys.
this is how it looks like:
or the code view:
{
"allScalesJson": [
{
"scale": "A Major",
"keys": [
"b",
"a",
"e",
"d",
"gs",
"fs",
"cs"
]
},
{
"scale": "B Major",
"keys": [
"b",
"e",
"as",
"gs",
"fs",
"ds",
"cs"
]
},
{
"scale": "D Major",
"keys": [
"b",
"a",
"g",
"e",
"d",
"fs",
"cs"
]
}
]
}
I'm trying to create a method that will take keys as parameter and return all scales that contains those keys.
Example based on above json data:
List<String> returned_scales = findScalesThatContainThisKeys(Arrays.asList("a","d"));
output:
A Major, D Major
Here it is:
private List<String> findScalesThatContainThisKeys(List<String> keys_array){
List<String> foundedScales = new ArrayList<>();
try {
JSONObject jsonObj = new JSONObject(loadJSONFromAsset());
JSONArray rootElement = jsonObj.getJSONArray("allScalesJson");
for (int i = 0; i < rootElement.length(); i++) {
JSONObject obj = rootElement.getJSONObject(i);
String scale = obj.getString("scale");
// Keys is json array
JSONArray genreArray = obj.getJSONArray("keys");
ArrayList<String> keys = new ArrayList<>();
for (int j = 0; j < genreArray.length(); j++) {
// TODO: 5/12/2018
}
}
}catch (Exception e){e.printStackTrace();}
return foundedScales;
}

keys_arrayList should match ? or one item match is ik?