Рубрики
Uncategorized

Интерфейс API данных баскетбола – пример кода для вызова API [данные анализа баскетбольной игры]

Автор оригинала: David Wong.

Для получения более подробной информации, пожалуйста, обратитесь к интерфейсному документу и зарегистрируйтесь

package com.huaying.demo.basketball;
 
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
 
/**
 *18. Basketball game analysis data
 *
 * @Website: https://www.feijing88.com
 */
public class BasketballMatchStatistics {
 
    public static void main(String[] args) {
        try {
            String content = getContent();
 
            Statistics statistics = Statistics.parseFrom(content);
            System.out.println(statistics);
 
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
 
    /**
     *Get API return content
     * 

*Note: in order to facilitate the test, I used a local file, which should be replaced with the real interface to return the content. */ private static String getContent() { try { StringBuilder builder = new StringBuilder(); List lines = Files.readAllLines(Paths.get("./src/main/resources/BasketballMatchStatistics.txt"), StandardCharsets.UTF_8); lines.forEach(line -> { builder.append(line); builder.append("|"); }); return builder.toString(); } catch (Throwable t) { t.printStackTrace(); return ""; } } public static class Statistics { private List vsRecord; private List homeRecentRecord; private List awayRecentRecord; private List homeFuture; private List awayFuture; public static Statistics parseFrom(String data) { Statistics statistics = new Statistics(); statistics.parse(data); return statistics; } private void parse(String date) { String[] values = date.split("\$\|"); int i = 0; vsRecord = Arrays.asList(values[i++].split("\|")); homeRecentRecord = Arrays.asList(values[i++].split("\|")); awayRecentRecord = Arrays.asList(values[i++].split("\|")); homeFuture = Arrays.asList(values[i++].split("\|")); awayFuture = Arrays.asList(values[i].split("\|")); } @Override public String toString() { return "Statistics{" + "\nvsRecord=" + vsRecord + ", \nhomeRecentRecord=" + homeRecentRecord + ", \nawayRecentRecord=" + awayRecentRecord + ", \nhomeFuture=" + homeFuture + ", \nawayFuture=" + awayFuture + "\n}"; } } }