/* * Copyright (c) 2017-2020. Developed by Hedgecode. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.hedgecode.snooker.cache.assign; import org.hedgecode.snooker.api.APIException; import org.hedgecode.snooker.api.Match; import org.hedgecode.snooker.api.Player; import org.hedgecode.snooker.json.JsonMatch; /** * Assigner for Entity fields of {@link Match}. * * @author Dmitry Samoshin aka gotty */ public class MatchAssigner extends CacheIdAssigner { private static MatchAssigner _instance; private MatchAssigner() { } public static MatchAssigner getInstance() { if (_instance == null) _instance = new MatchAssigner(); return _instance; } @Override public void assign(Match match) throws APIException { JsonMatch jsonMatch = (JsonMatch) match; jsonMatch.setEvent( cacheScore.getCachedEvent( match.eventId() ) ); Player player1 = cacheScore.getCachedPlayer( match.player1Id() ); Player player2 = cacheScore.getCachedPlayer( match.player2Id() ); jsonMatch.setPlayer1(player1); jsonMatch.setPlayer2(player2); jsonMatch.setWinner( match.winnerId() == match.player1Id() ? player1 : match.winnerId() == match.player2Id() ? player2 : null ); } }