private HighTideValues findHighTide(JSONObject responseObject) throws JSONException, ParseException {
  JSONArray predictions=(JSONArray)responseObject.get("predictions");
  JSONObject lastPrediction=null, firstHighTide=null, secondHighTide=null, lowTide=null;
  boolean firstTideDone=false;
  for (int i=0; i < predictions.length(); i++) {
    JSONObject prediction=(JSONObject)predictions.get(i);
    if (lastPrediction == null) {
      lastPrediction=prediction;
      continue;
    }
    if (isTideIncreasing(lastPrediction,prediction)) {
      if (!firstTideDone) {
        firstHighTide=prediction;
      }
 else {
        secondHighTide=prediction;
      }
    }
 else {
      if (!firstTideDone && firstHighTide != null) {
        firstTideDone=true;
      }
 else       if (secondHighTide != null) {
        break;
      }
      if (firstTideDone) {
        lowTide=prediction;
      }
    }
    lastPrediction=prediction;
  }
  DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-d HH:mm");
  return new HighTideValues(AlexaDateUtil.getFormattedTime(dateFormat.parse(firstHighTide.getString("t"))),getFormattedHeight(firstHighTide.getString("v")),AlexaDateUtil.getFormattedTime(dateFormat.parse(lowTide.getString("t"))),getFormattedHeight(lowTide.getString("v")),AlexaDateUtil.getFormattedTime(dateFormat.parse(secondHighTide.getString("t"))),getFormattedHeight(secondHighTide.getString("v")));
}

private HighTideValues findHighTide ( JSONObject responseObject ) throws JSONException , ParseException { JSONArray predictions = ( JSONArray ) responseObject . get ( "predictions" ) ; JSONObject lastPrediction = null , firstHighTide = null , secondHighTide = null , lowTide = null ; boolean firstTideDone = false ; for ( int i = 0 ; i < predictions . length ( ) ; i ++ ) { JSONObject prediction = ( JSONObject ) predictions . get ( i ) ; if ( lastPrediction == null ) { lastPrediction = prediction ; continue ; } if ( isTideIncreasing ( lastPrediction , prediction ) ) { if ( ! firstTideDone ) { firstHighTide = prediction ; } else { secondHighTide = prediction ; } } else { if ( ! firstTideDone && firstHighTide != null ) { firstTideDone = true ; } else if ( secondHighTide != null ) { break ; } if ( firstTideDone ) { lowTide = prediction ; } } lastPrediction = prediction ; } DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-d HH:mm" ) ; return new HighTideValues ( AlexaDateUtil . getFormattedTime ( dateFormat . parse ( firstHighTide . getString ( "t" ) ) ) , getFormattedHeight ( firstHighTide . getString ( "v" ) ) , AlexaDateUtil . getFormattedTime ( dateFormat . parse ( lowTide . getString ( "t" ) ) ) , getFormattedHeight ( lowTide . getString ( "v" ) ) , AlexaDateUtil . getFormattedTime ( dateFormat . parse ( secondHighTide . getString ( "t" ) ) ) , getFormattedHeight ( secondHighTide . getString ( "v" ) ) ) ; }
algorithm to find the 2 high tides for the day , the first of which is smaller and occurs mid - day , the second of which is larger and typically in the evening .
