具有多个层的Java Map

时间:2017-02-08 08:11:04

标签: java dictionary

我正在尝试将下面的数据转换为某种形式的Java结构。 这些数据代表了一场网球锦标赛,乔以6比3,6比4击败肯,而莎莉则以6比4,2比6,6比1击败露西。 据我所知,我应该可以使用法线贴图,如Map1<Key1, Map2<Key2, Map3<Key3, Value>>> 让我失望的是,每次我都不会进入最后一层( GameResult )。查看 FixtureResult MatchResult 的变量作为例子。此外,每个 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>

1 个答案:

答案 0 :(得分:0)

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

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;
}