package org.jeecg.sy.temp

import com.alibaba.fastjson.{JSONArray, JSONObject}
import org.jeecg.sy.java.{weather_1, weather_2}

import java.text.{ParseException, SimpleDateFormat}
import java.util
import java.util.{Collections, Comparator, List}

object analysis {
  // 数据爬取，输入一个List[weather_1]，返回处理完的数据
  def getData(list: List[weather_1]): List[weather_1] = {
    // 将list 倒序// 将list 倒序
    for (i <- 0 until list.size / 2) {
      val temp: weather_1 = list.get(i)
      list.set(i, list.get(list.size - i - 1))
      list.set(list.size - i - 1, temp)
    }
    return list
  }

  def analysis2(list: List[weather_1]): List[weather_1] = {
    // 先将list按照时间排序，旧的在前面，新的在后面
    // 先将list按照时间排序，旧的在前面，新的在后面
    val sdf: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
    Collections.sort(list, new Comparator[weather_1]() {
      override def compare(d1: weather_1, d2: weather_1): Int = {
        try return sdf.parse(d1.getData).compareTo(sdf.parse(d2.getData))
        catch {
          case e: ParseException =>
            throw new IllegalArgumentException(e)
        }
      }
    })
    list
  }

  def analysis3(list: List[weather_2]): List[weather_2] = {
    list
  }

}
