gpt4 book ai didi

具有多层的 Java Map

转载 作者:太空宇宙 更新时间:2023-11-04 11:48:16 24 4
gpt4 key购买 nike

我正在尝试将下面的数据转换为某种形式的 Java 结构。数据代表一场网球锦标赛,乔以 6-3、6-4 击败肯,莎莉以 6-4、2-6、6-1 击败露西。据我所知,我应该能够使用法线贴图,像这样 Map1<Key1, Map2<Key2, Map3<Key3, Value>>>让我失望的是我不会每次都进入最后一层(GameResult)。以 FixtureResultMatchResult 的变量为例。此外,每个 MatchResult 都会有多个 GameResult 集,那么如何从 MatchResult(父)角度为这些 GameResult 对象提供唯一的键?

<FixtureResult>
<Id>1</Id>
<FixtureId>1</FixtureId>
<DateSubmitted>07-01-2017</DateSubmitted>

<MatchResult>
<Id>1</Id>
<WinnerName>Joe</WinnerName>
<LoserName>Ken</LoserName>

<GameResult>
<Id>1</Id>
<WinnerPoints>6</WinnerPoints>
<LoserPoints>3</LoserPoints>
<Ordinal>1</Ordinal>
</GameResult>

<GameResult>
<Id>2</Id>
<WinnerPoints>6</WinnerPoints>
<LoserPoints>4</LoserPoints>
<Ordinal>2</Ordinal>
</GameResult>

</MatchResult>

<MatchResult>
<Id>2</Id>
<WinnerName>Sally</WinnerName>
<LoserName>Lucy</LoserName>

<GameResult>
<Id>3</Id>
<WinnerPoints>6</WinnerPoints>
<LoserPoints>4</LoserPoints>
<Ordinal>1</Ordinal>
</GameResult>

<GameResult>
<Id>4</Id>
<WinnerPoints>2</WinnerPoints>
<LoserPoints>6</LoserPoints>
<Ordinal>2</Ordinal>
</GameResult>

<GameResult>
<Id>5</Id>
<WinnerPoints>6</WinnerPoints>
<LoserPoints>1</LoserPoints>
<Ordinal>3</Ordinal>
</GameResult>

</MatchResult>
</FixtureResult>

最佳答案

为什么不使用您定义的结构?

class FixtureResult {
Integer id;
Integer FixtureId;
Date dateSubmitted;
List<MatchResult> matchResults
}
class MatchResult {
Integer id;
String winnerName;
String loserName;
List<GameResult> gameResults
}
class GameResult {
Integer id;
Integer winnerPoints;
Integer loserPoints;
Integer ordinal;
}

关于具有多层的 Java Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42107784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com