<?xml version='1.0' encoding='UTF-8'?>
<!--
- ~ Copyright (c) 2017. Developed by Hedgecode.
+ ~ Copyright (c) 2017-2019. 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.
<groupId>org.hedgecode.snooker</groupId>
<artifactId>snooker-score-api</artifactId>
- <version>0.1</version>
+ <version>0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Hedgecode Snooker Score API</name>
<mavenDependencyPluginVersion>2.8</mavenDependencyPluginVersion>
<mavenAssemblyPluginVersion>2.4.1</mavenAssemblyPluginVersion>
<issueComponentId>10012</issueComponentId>
- <issueNumber>5</issueNumber>
+ <issueNumber>8</issueNumber>
</properties>
<dependencies>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<sourceFileExcludes>
- <exclude>org//hedgecode/snooker/cache/assign/*.java</exclude>
- <exclude>org//hedgecode/snooker/compare/*.java</exclude>
- <exclude>org//hedgecode/snooker/gson/*.java</exclude>
- <exclude>org//hedgecode/snooker/json/*.java</exclude>
- <exclude>org//hedgecode/snooker/request/*.java</exclude>
+ <exclude>org/hedgecode/snooker/annotation/*.java</exclude>
+ <exclude>org/hedgecode/snooker/cache/assign/*.java</exclude>
+ <exclude>org/hedgecode/snooker/compare/*.java</exclude>
+ <exclude>org/hedgecode/snooker/gson/*.java</exclude>
+ <exclude>org/hedgecode/snooker/json/*.java</exclude>
+ <exclude>org/hedgecode/snooker/request/*.java</exclude>
</sourceFileExcludes>
</configuration>
</plugin>
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.api;
+
+/**
+ * Round Entity API Interface.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public interface Round extends IdEntity {
+
+ int round();
+
+ String roundName();
+
+ int eventId();
+
+ Event event();
+
+ int mainEventId();
+
+ Event mainEvent();
+
+ int distance();
+
+ int numLeft();
+
+ int numMatches();
+
+ String note();
+
+ String valueType();
+
+ int rank();
+
+ long money();
+
+ int seedGetsHalf();
+
+ long actualMoney();
+
+ String currency();
+
+ int conversionRate();
+
+ int points();
+
+ int seedPoints();
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.api;
+
+/**
+ * Rounds Entity (set of {@link Round}) API Interface.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public interface Rounds extends CollectionEntity<Round> {
+
+ Round byRound(int roundId);
+ Rounds byRoundName(String roundName);
+ Rounds byEvent(int eventId);
+ Rounds byMainEvent(int mainEventId);
+
+ void sortByRound();
+ void sortByEvent();
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.api;
+
+/**
+ * Seeding Entity API Interface.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public interface Seeding extends IdEntity {
+
+ int eventId();
+
+ Event event();
+
+ int playerId();
+
+ Player player();
+
+ int seeding();
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.api;
+
+/**
+ * Seedings Entity (set of {@link Seeding}) API Interface.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public interface Seedings extends CollectionEntity<Seeding> {
+
+ Seedings byEvent(int eventId);
+ Seeding byPlayer(int playerId);
+ Seeding bySeeding(int seedingNum);
+
+ void sortByEvent();
+ void sortByPlayer();
+ void sortBySeeding();
+
+}
Rankings getRankings(Season season, RankingType type) throws APIException;
+ Rounds getEventRounds(int eventId) throws APIException;
+
+ Seedings getEventSeedings(int eventId) throws APIException;
+
void setCurrentSeason(Season season) throws APIException;
Season currentSeason() throws APIException;
import org.hedgecode.snooker.api.Players;
import org.hedgecode.snooker.api.RankingType;
import org.hedgecode.snooker.api.Rankings;
+import org.hedgecode.snooker.api.Rounds;
import org.hedgecode.snooker.api.Season;
+import org.hedgecode.snooker.api.Seedings;
import org.hedgecode.snooker.api.SnookerScoreAPI;
import org.hedgecode.snooker.cache.assign.EventAssigner;
import org.hedgecode.snooker.cache.assign.EventsAssigner;
import org.hedgecode.snooker.cache.assign.MatchAssigner;
import org.hedgecode.snooker.cache.assign.MatchesAssigner;
import org.hedgecode.snooker.cache.assign.RankingsAssigner;
+import org.hedgecode.snooker.cache.assign.RoundsAssigner;
+import org.hedgecode.snooker.cache.assign.SeedingsAssigner;
import org.hedgecode.snooker.json.JsonSnookerScore;
/**
private final EventsAssigner eventsAssigner = EventsAssigner.getInstance();
private final MatchesAssigner matchesAssigner = MatchesAssigner.getInstance();
private final RankingsAssigner rankingsAssigner = RankingsAssigner.getInstance();
+ private final RoundsAssigner roundsAssigner = RoundsAssigner.getInstance();
+ private final SeedingsAssigner seedingsAssigner = SeedingsAssigner.getInstance();
private static CacheSnookerScore _instance;
return rankings;
}
+ @Override
+ public Rounds getEventRounds(int eventId) throws APIException {
+ Rounds rounds = super.getEventRounds(eventId);
+ roundsAssigner.assign(rounds);
+ return rounds;
+ }
+
+ @Override
+ public Seedings getEventSeedings(int eventId) throws APIException {
+ Seedings seedings = super.getEventSeedings(eventId);
+ seedingsAssigner.assign(seedings);
+ return seedings;
+ }
+
}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.Round;
+import org.hedgecode.snooker.json.JsonRound;
+
+/**
+ * Assigner for Entity fields of {@link Round}.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class RoundAssigner extends CacheIdAssigner<Round> {
+
+ private static RoundAssigner _instance;
+
+ private RoundAssigner() {
+ }
+
+ public static RoundAssigner getInstance() {
+ if (_instance == null)
+ _instance = new RoundAssigner();
+ return _instance;
+ }
+
+ @Override
+ public void assign(Round round) throws APIException {
+ JsonRound jsonRound = (JsonRound) round;
+ jsonRound.setEvent(
+ cacheScore.getCachedEvent(
+ round.eventId()
+ )
+ );
+ jsonRound.setMainEvent(
+ cacheScore.getCachedEvent(
+ round.mainEventId()
+ )
+ );
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.Round;
+import org.hedgecode.snooker.api.Rounds;
+
+/**
+ * Assigner for Collections of Entities {@link Round}.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class RoundsAssigner
+ extends CacheCollectionAssigner<Round, Rounds, RoundAssigner>
+{
+ private static RoundsAssigner _instance;
+
+ private RoundsAssigner() {
+ super(
+ RoundAssigner.getInstance()
+ );
+ }
+
+ public static RoundsAssigner getInstance() {
+ if (_instance == null)
+ _instance = new RoundsAssigner();
+ return _instance;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.Seeding;
+import org.hedgecode.snooker.json.JsonSeeding;
+
+/**
+ * Assigner for Entity fields of {@link Seeding}.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class SeedingAssigner extends CacheIdAssigner<Seeding> {
+
+ private static SeedingAssigner _instance;
+
+ private SeedingAssigner() {
+ }
+
+ public static SeedingAssigner getInstance() {
+ if (_instance == null)
+ _instance = new SeedingAssigner();
+ return _instance;
+ }
+
+ @Override
+ public void assign(Seeding seeding) throws APIException {
+ JsonSeeding jsonSeeding = (JsonSeeding) seeding;
+ jsonSeeding.setEvent(
+ cacheScore.getCachedEvent(
+ seeding.eventId()
+ )
+ );
+ jsonSeeding.setPlayer(
+ cacheScore.getCachedPlayer(
+ seeding.playerId()
+ )
+ );
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.Seeding;
+import org.hedgecode.snooker.api.Seedings;
+
+/**
+ * Assigner for Collections of Entities {@link Seeding}.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class SeedingsAssigner
+ extends CacheCollectionAssigner<Seeding, Seedings, SeedingAssigner>
+{
+ private static SeedingsAssigner _instance;
+
+ private SeedingsAssigner() {
+ super(
+ SeedingAssigner.getInstance()
+ );
+ }
+
+ public static SeedingsAssigner getInstance() {
+ if (_instance == null)
+ _instance = new SeedingsAssigner();
+ return _instance;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.compare;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.hedgecode.snooker.api.Round;
+
+/**
+ * Set of Comparators for {@link Round}.
+ * 1. Sorting by Round Number {@link RoundComparator};
+ * 2. Sorting by Event {@link EventComparator};
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public enum RoundComparators {
+
+ ROUND ( new RoundComparator() ),
+ EVENT ( new EventComparator() );
+
+ private Comparator<Round> comparator;
+
+ RoundComparators(Comparator<Round> comparator) {
+ this.comparator = comparator;
+ }
+
+ public Comparator<Round> comparator() {
+ return comparator;
+ }
+
+ static class RoundComparator implements Comparator<Round>, Serializable {
+
+ @Override
+ public int compare(Round round1, Round round2) {
+ return round1.round() - round2.round();
+ }
+
+ }
+
+ static class EventComparator implements Comparator<Round>, Serializable {
+
+ @Override
+ public int compare(Round round1, Round round2) {
+ return round1.eventId() - round2.eventId();
+ }
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.compare;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.hedgecode.snooker.api.Seeding;
+
+/**
+ * Set of Comparators for {@link Seeding}.
+ * 1. Sorting by Event {@link EventComparator};
+ * 2. Sorting by Player {@link PlayerComparator};
+ * 3. Sorting by Seeding Number {@link SeedingComparator}.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public enum SeedingComparators {
+
+ EVENT ( new EventComparator() ),
+ PLAYER ( new PlayerComparator() ),
+ SEEDING ( new SeedingComparator() );
+
+ private Comparator<Seeding> comparator;
+
+ SeedingComparators(Comparator<Seeding> comparator) {
+ this.comparator = comparator;
+ }
+
+ public Comparator<Seeding> comparator() {
+ return comparator;
+ }
+
+ static class EventComparator implements Comparator<Seeding>, Serializable {
+
+ @Override
+ public int compare(Seeding seeding1, Seeding seeding2) {
+ return seeding1.eventId() - seeding2.eventId();
+ }
+
+ }
+
+ static class PlayerComparator implements Comparator<Seeding>, Serializable {
+
+ @Override
+ public int compare(Seeding seeding1, Seeding seeding2) {
+ return seeding1.playerId() - seeding2.playerId();
+ }
+
+ }
+
+ static class SeedingComparator implements Comparator<Seeding>, Serializable {
+
+ @Override
+ public int compare(Seeding seeding1, Seeding seeding2) {
+ return seeding1.seeding() - seeding2.seeding();
+ }
+
+ }
+
+}
package org.hedgecode.snooker.json;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.json;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+
+import org.hedgecode.snooker.api.Event;
+import org.hedgecode.snooker.api.Round;
+
+/**
+ * Round Entity to JSON deserialize.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class JsonRound extends JsonIdEntity implements Round {
+
+ @SerializedName("Round")
+ private int round;
+ @SerializedName("RoundName")
+ private String roundName;
+ @SerializedName("EventID")
+ private int eventId;
+ @Expose
+ private Event event;
+ @SerializedName("MainEvent")
+ private int mainEventId;
+ @Expose
+ private Event mainEvent;
+ @SerializedName("Distance")
+ private int distance;
+ @SerializedName("NumLeft")
+ private int numLeft;
+ @SerializedName("NumMatches")
+ private int numMatches;
+ @SerializedName("Note")
+ private String note;
+ @SerializedName("ValueType")
+ private String valueType;
+ @SerializedName("Rank")
+ private int rank;
+ @SerializedName("Money")
+ private long money;
+ @SerializedName("SeedGetsHalf")
+ private int seedGetsHalf;
+ @SerializedName("ActualMoney")
+ private long actualMoney;
+ @SerializedName("Currency")
+ private String currency;
+ @SerializedName("ConversionRate")
+ private int conversionRate;
+ @SerializedName("Points")
+ private int points;
+ @SerializedName("SeedPoints")
+ private int seedPoints;
+
+ protected JsonRound() {
+ }
+
+ @Override
+ public int round() {
+ return round;
+ }
+
+ @Override
+ public String roundName() {
+ return roundName;
+ }
+
+ @Override
+ public int eventId() {
+ return eventId;
+ }
+
+ @Override
+ public Event event() {
+ return event;
+ }
+
+ public void setEvent(Event event) {
+ if (event != null && eventId == event.eventId())
+ this.event = event;
+ }
+
+ @Override
+ public int mainEventId() {
+ return mainEventId;
+ }
+
+ @Override
+ public Event mainEvent() {
+ return mainEvent;
+ }
+
+ public void setMainEvent(Event mainEvent) {
+ if (mainEvent != null && mainEventId == mainEvent.eventId())
+ this.mainEvent = mainEvent;
+ }
+
+ @Override
+ public int distance() {
+ return distance;
+ }
+
+ @Override
+ public int numLeft() {
+ return numLeft;
+ }
+
+ @Override
+ public int numMatches() {
+ return numMatches;
+ }
+
+ @Override
+ public String note() {
+ return note;
+ }
+
+ @Override
+ public String valueType() {
+ return valueType;
+ }
+
+ @Override
+ public int rank() {
+ return rank;
+ }
+
+ @Override
+ public long money() {
+ return money;
+ }
+
+ @Override
+ public int seedGetsHalf() {
+ return seedGetsHalf;
+ }
+
+ @Override
+ public long actualMoney() {
+ return actualMoney;
+ }
+
+ @Override
+ public String currency() {
+ return currency;
+ }
+
+ @Override
+ public int conversionRate() {
+ return conversionRate;
+ }
+
+ @Override
+ public int points() {
+ return points;
+ }
+
+ @Override
+ public int seedPoints() {
+ return seedPoints;
+ }
+
+ @Override
+ public int getId() {
+ return round;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.json;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hedgecode.snooker.api.Round;
+import org.hedgecode.snooker.api.Rounds;
+import org.hedgecode.snooker.compare.RoundComparators;
+
+/**
+ * Rounds Entity (set of {@link Round}) to JSON deserialize.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class JsonRounds extends JsonCollectionEntity<Round> implements Rounds {
+
+ private static final JsonRounds EMPTY = new JsonRounds(new Round[0]);
+
+ protected JsonRounds(Round[] entities) {
+ super(entities);
+ }
+
+ protected JsonRounds(List<Round> entities) {
+ super(entities);
+ }
+
+ @Override
+ public Round byRound(int roundId) {
+ for (Round round : this)
+ if (round.round() == roundId)
+ return round;
+ return null;
+ }
+
+ @Override
+ public Rounds byRoundName(String roundName) {
+ if (roundName == null || roundName.isEmpty())
+ return EMPTY;
+ List<Round> rounds = new ArrayList<>();
+ for (Round round : this)
+ if (roundName.equals(round.roundName()))
+ rounds.add(round);
+ return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
+ }
+
+ @Override
+ public Rounds byEvent(int eventId) {
+ List<Round> rounds = new ArrayList<>();
+ for (Round round : this)
+ if (round.eventId() == eventId)
+ rounds.add(round);
+ return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
+ }
+
+ @Override
+ public Rounds byMainEvent(int mainEventId) {
+ List<Round> rounds = new ArrayList<>();
+ for (Round round : this)
+ if (round.mainEventId() == mainEventId)
+ rounds.add(round);
+ return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
+ }
+
+ @Override
+ public void sortByRound() {
+ sort(
+ RoundComparators.ROUND.comparator()
+ );
+ }
+
+ @Override
+ public void sortByEvent() {
+ sort(
+ RoundComparators.EVENT.comparator()
+ );
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.json;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+
+import org.hedgecode.snooker.api.Event;
+import org.hedgecode.snooker.api.Player;
+import org.hedgecode.snooker.api.Seeding;
+
+/**
+ * Seeding Entity to JSON deserialize.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class JsonSeeding extends JsonIdEntity implements Seeding {
+
+ @SerializedName("EventID")
+ private int eventId;
+ @Expose
+ private Event event;
+ @SerializedName("PlayerID")
+ private int playerId;
+ @Expose
+ private Player player;
+ @SerializedName("Seeding")
+ private int seeding;
+
+ protected JsonSeeding() {
+ }
+
+ @Override
+ public int eventId() {
+ return eventId;
+ }
+
+ @Override
+ public Event event() {
+ return event;
+ }
+
+ public void setEvent(Event event) {
+ if (event != null && eventId == event.eventId())
+ this.event = event;
+ }
+
+ @Override
+ public int playerId() {
+ return playerId;
+ }
+
+ @Override
+ public Player player() {
+ return player;
+ }
+
+ public void setPlayer(Player player) {
+ if (player != null && playerId == player.playerId())
+ this.player = player;
+ }
+
+ @Override
+ public int seeding() {
+ return seeding;
+ }
+
+ @Override
+ public int getId() {
+ return seeding;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.json;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hedgecode.snooker.api.Seeding;
+import org.hedgecode.snooker.api.Seedings;
+import org.hedgecode.snooker.compare.SeedingComparators;
+
+/**
+ * Seedings Entity (set of {@link Seeding}) to JSON deserialize.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class JsonSeedings extends JsonCollectionEntity<Seeding> implements Seedings {
+
+ private static final JsonSeedings EMPTY = new JsonSeedings(new Seeding[0]);
+
+ protected JsonSeedings(Seeding[] entities) {
+ super(entities);
+ }
+
+ protected JsonSeedings(List<Seeding> entities) {
+ super(entities);
+ }
+
+ @Override
+ public Seedings byEvent(int eventId) {
+ List<Seeding> seedings = new ArrayList<>();
+ for (Seeding seeding : this)
+ if (seeding.eventId() == eventId)
+ seedings.add(seeding);
+ return seedings.isEmpty() ? EMPTY : new JsonSeedings(seedings);
+ }
+
+ @Override
+ public Seeding byPlayer(int playerId) {
+ for (Seeding seeding : this)
+ if (seeding.playerId() == playerId)
+ return seeding;
+ return null;
+ }
+
+ @Override
+ public Seeding bySeeding(int seedingNum) {
+ for (Seeding seeding : this)
+ if (seeding.seeding() == seedingNum)
+ return seeding;
+ return null;
+ }
+
+ @Override
+ public void sortByEvent() {
+ sort(
+ SeedingComparators.EVENT.comparator()
+ );
+ }
+
+ @Override
+ public void sortByPlayer() {
+ sort(
+ SeedingComparators.PLAYER.comparator()
+ );
+ }
+
+ @Override
+ public void sortBySeeding() {
+ sort(
+ SeedingComparators.SEEDING.comparator()
+ );
+ }
+
+}
import org.hedgecode.snooker.api.Players;
import org.hedgecode.snooker.api.RankingType;
import org.hedgecode.snooker.api.Rankings;
+import org.hedgecode.snooker.api.Rounds;
import org.hedgecode.snooker.api.Season;
+import org.hedgecode.snooker.api.Seedings;
import org.hedgecode.snooker.api.SnookerScoreAPI;
import org.hedgecode.snooker.gson.SnookerGsonBuilder;
import org.hedgecode.snooker.request.RequestException;
}
@Override
+ public Rounds getEventRounds(int eventId) throws APIException {
+ Rounds rounds;
+ try {
+ rounds = new JsonRounds(
+ GSON.fromJson(
+ JsonStringToken.token(
+ RequestType.request(
+ RequestType.EVENT_ROUNDS,
+ eventId
+ )
+ ),
+ JsonRound[].class
+ )
+ );
+ } catch (RequestException e) {
+ throw new APIException(
+ APIException.Type.REQUEST, e.getMessage()
+ );
+ }
+ return rounds;
+ }
+
+ @Override
+ public Seedings getEventSeedings(int eventId) throws APIException {
+ Seedings seedings;
+ try {
+ seedings = new JsonSeedings(
+ GSON.fromJson(
+ JsonStringToken.token(
+ RequestType.request(
+ RequestType.EVENT_SEEDING,
+ eventId
+ )
+ ),
+ JsonSeeding[].class
+ )
+ );
+ } catch (RequestException e) {
+ throw new APIException(
+ APIException.Type.REQUEST, e.getMessage()
+ );
+ }
+ return seedings;
+ }
+
+ @Override
public void setCurrentSeason(Season season) throws APIException {
throw new APIException(
APIException.Type.INFO, "This feature is only available in Cached API"
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.request;
+
+/**
+ * Requester of Rounds Info for an Event.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class EventRoundsRequester extends AbstractRequester {
+
+ private static final String EVENT_ROUNDS_URL = API_SNOOKER_URL + "?t=12&e=[EventID]";
+
+ private static final Requester _instance = new EventRoundsRequester();
+
+ private EventRoundsRequester() {
+ }
+
+ public static Requester getInstance() {
+ return _instance;
+ }
+
+ @Override
+ protected String getRequestUrl(int id) throws RequestException {
+ if (!isCorrectId(id))
+ throw new RequestException(EVENT_ROUNDS_URL, "Incorrect Event ID");
+
+ return EVENT_ROUNDS_URL.replace(
+ "[EventID]", String.valueOf(id)
+ );
+ }
+
+ @Override
+ protected String getRequestUrl(RequestParams params) throws RequestException {
+ if (params == null || !isCorrectId(params.getEventId()))
+ throw new RequestException(EVENT_ROUNDS_URL, "Incorrect Event ID");
+
+ return EVENT_ROUNDS_URL.replace(
+ "[EventID]", String.valueOf(params.getEventId())
+ );
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2017-2019. 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.request;
+
+/**
+ * Requester of Seeding for an Event.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+public class EventSeedingRequester extends AbstractRequester {
+
+ private static final String EVENT_SEEDING_URL = API_SNOOKER_URL + "?t=13&e=[EventID]";
+
+ private static final Requester _instance = new EventSeedingRequester();
+
+ private EventSeedingRequester() {
+ }
+
+ public static Requester getInstance() {
+ return _instance;
+ }
+
+ @Override
+ protected String getRequestUrl(int id) throws RequestException {
+ if (!isCorrectId(id))
+ throw new RequestException(EVENT_SEEDING_URL, "Incorrect Event ID");
+
+ return EVENT_SEEDING_URL.replace(
+ "[EventID]", String.valueOf(id)
+ );
+ }
+
+ @Override
+ protected String getRequestUrl(RequestParams params) throws RequestException {
+ if (params == null || !isCorrectId(params.getEventId()))
+ throw new RequestException(EVENT_SEEDING_URL, "Incorrect Event ID");
+
+ return EVENT_SEEDING_URL.replace(
+ "[EventID]", String.valueOf(params.getEventId())
+ );
+ }
+
+}
PLAYER_MATCHES ( PlayerMatchesRequester.getInstance() ),
EVENT_PLAYERS ( EventPlayersRequester.getInstance() ),
SEASON_PLAYERS ( SeasonPlayersRequester.getInstance() ),
- RANKING ( RankingRequester.getInstance() );
+ RANKING ( RankingRequester.getInstance() ),
+ EVENT_ROUNDS ( EventRoundsRequester.getInstance() ),
+ EVENT_SEEDING ( EventSeedingRequester.getInstance() );
private Requester requester;
--- /dev/null
+[{"Round": 1,"RoundName": "Qual Round 1","EventID": 398,"MainEvent": 403,"Distance": 5,"NumLeft": 128,"NumMatches": 32,"Note": "","ValueType": "SM","Rank": 160,"Money": 0,"SeedGetsHalf": 1,"ActualMoney": 0,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0}]
\ No newline at end of file
--- /dev/null
+[{"Round": 1,"RoundName": "Qual Round 1","EventID": 398,"MainEvent": 403,"Distance": 5,"NumLeft": 128,"NumMatches": 32,"Note": "","ValueType": "SM","Rank": 160,"Money": 0,"SeedGetsHalf": 1,"ActualMoney": 0,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 2,"RoundName": "Qual Round 2","EventID": 398,"MainEvent": 403,"Distance": 5,"NumLeft": 96,"NumMatches": 32,"Note": "","ValueType": "SM","Rank": 150,"Money": 500,"SeedGetsHalf": 1,"ActualMoney": 500,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 3,"RoundName": "Qual Round 3","EventID": 398,"MainEvent": 403,"Distance": 5,"NumLeft": 64,"NumMatches": 16,"Note": "","ValueType": "SM","Rank": 140,"Money": 2000,"SeedGetsHalf": 0,"ActualMoney": 2000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 4,"RoundName": "Qual Round 4","EventID": 398,"MainEvent": 403,"Distance": 5,"NumLeft": 48,"NumMatches": 16,"Note": "","ValueType": "SM","Rank": 130,"Money": 3000,"SeedGetsHalf": 1,"ActualMoney": 3000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 16,"RoundName": "Wild Card Round","EventID": 403,"MainEvent": 403,"Distance": 5,"NumLeft": 40,"NumMatches": 8,"Note": "","ValueType": "SM","Rank": 100,"Money": 6000,"SeedGetsHalf": 0,"ActualMoney": 6000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 7,"RoundName": "Round 1","EventID": 403,"MainEvent": 403,"Distance": 5,"NumLeft": 32,"NumMatches": 16,"Note": "","ValueType": "SM","Rank": 90,"Money": 6000,"SeedGetsHalf": 1,"ActualMoney": 6000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 8,"RoundName": "Round 2","EventID": 403,"MainEvent": 403,"Distance": 5,"NumLeft": 16,"NumMatches": 8,"Note": "","ValueType": "SM","Rank": 80,"Money": 8000,"SeedGetsHalf": 0,"ActualMoney": 8000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 13,"RoundName": "Quarterfinals","EventID": 403,"MainEvent": 403,"Distance": 5,"NumLeft": 8,"NumMatches": 4,"Note": "","ValueType": "SM","Rank": 30,"Money": 12000,"SeedGetsHalf": 0,"ActualMoney": 12000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 14,"RoundName": "Semifinals","EventID": 403,"MainEvent": 403,"Distance": 6,"NumLeft": 4,"NumMatches": 2,"Note": "","ValueType": "SM","Rank": 20,"Money": 19500,"SeedGetsHalf": 0,"ActualMoney": 19500,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 15,"RoundName": "Final","EventID": 403,"MainEvent": 403,"Distance": 10,"NumLeft": 2,"NumMatches": 1,"Note": "","ValueType": "SM","Rank": 10,"Money": 35000,"SeedGetsHalf": 0,"ActualMoney": 35000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0},{"Round": 17,"RoundName": "Final","EventID": 403,"MainEvent": 403,"Distance": 0,"NumLeft": 1,"NumMatches": 0,"Note": "","ValueType": "SM","Rank": 5,"Money": 85000,"SeedGetsHalf": 0,"ActualMoney": 85000,"Currency": "GBP","ConversionRate": 1,"Points": 0,"SeedPoints": 0}]
\ No newline at end of file
--- /dev/null
+[{"EventID": 403,"PlayerID": 30,"Seeding": 1}]
\ No newline at end of file
--- /dev/null
+[{"EventID": 403,"PlayerID": 30,"Seeding": 1},{"EventID": 403,"PlayerID": 17,"Seeding": 2},{"EventID": 403,"PlayerID": 224,"Seeding": 3},{"EventID": 403,"PlayerID": 154,"Seeding": 4},{"EventID": 403,"PlayerID": 97,"Seeding": 5},{"EventID": 403,"PlayerID": 12,"Seeding": 6},{"EventID": 403,"PlayerID": 16,"Seeding": 7},{"EventID": 403,"PlayerID": 168,"Seeding": 8},{"EventID": 403,"PlayerID": 62,"Seeding": 9},{"EventID": 403,"PlayerID": 202,"Seeding": 10},{"EventID": 403,"PlayerID": 237,"Seeding": 11},{"EventID": 403,"PlayerID": 4,"Seeding": 12},{"EventID": 403,"PlayerID": 1,"Seeding": 13},{"EventID": 403,"PlayerID": 2,"Seeding": 14},{"EventID": 403,"PlayerID": 171,"Seeding": 15},{"EventID": 403,"PlayerID": 52,"Seeding": 16},{"EventID": 403,"PlayerID": 15,"Seeding": 17},{"EventID": 403,"PlayerID": 92,"Seeding": 18},{"EventID": 403,"PlayerID": 68,"Seeding": 19},{"EventID": 403,"PlayerID": 200,"Seeding": 20},{"EventID": 403,"PlayerID": 24,"Seeding": 21},{"EventID": 403,"PlayerID": 22,"Seeding": 22},{"EventID": 403,"PlayerID": 125,"Seeding": 23},{"EventID": 403,"PlayerID": 27,"Seeding": 24},{"EventID": 403,"PlayerID": 44,"Seeding": 25},{"EventID": 403,"PlayerID": 63,"Seeding": 26},{"EventID": 403,"PlayerID": 47,"Seeding": 27},{"EventID": 403,"PlayerID": 158,"Seeding": 28},{"EventID": 403,"PlayerID": 42,"Seeding": 29},{"EventID": 403,"PlayerID": 10,"Seeding": 30},{"EventID": 403,"PlayerID": 546,"Seeding": 31},{"EventID": 403,"PlayerID": 19,"Seeding": 32},{"EventID": 403,"PlayerID": 9,"Seeding": 33},{"EventID": 403,"PlayerID": 28,"Seeding": 34},{"EventID": 403,"PlayerID": 177,"Seeding": 35},{"EventID": 403,"PlayerID": 61,"Seeding": 36},{"EventID": 403,"PlayerID": 118,"Seeding": 37},{"EventID": 403,"PlayerID": 33,"Seeding": 38},{"EventID": 403,"PlayerID": 38,"Seeding": 39},{"EventID": 403,"PlayerID": 48,"Seeding": 40},{"EventID": 403,"PlayerID": 93,"Seeding": 41},{"EventID": 403,"PlayerID": 53,"Seeding": 42},{"EventID": 403,"PlayerID": 101,"Seeding": 43},{"EventID": 403,"PlayerID": 54,"Seeding": 44},{"EventID": 403,"PlayerID": 217,"Seeding": 45},{"EventID": 403,"PlayerID": 170,"Seeding": 46},{"EventID": 403,"PlayerID": 25,"Seeding": 47},{"EventID": 403,"PlayerID": 96,"Seeding": 48},{"EventID": 403,"PlayerID": 108,"Seeding": 49},{"EventID": 403,"PlayerID": 582,"Seeding": 50},{"EventID": 403,"PlayerID": 85,"Seeding": 51},{"EventID": 403,"PlayerID": 184,"Seeding": 52},{"EventID": 403,"PlayerID": 39,"Seeding": 53},{"EventID": 403,"PlayerID": 190,"Seeding": 54},{"EventID": 403,"PlayerID": 295,"Seeding": 55},{"EventID": 403,"PlayerID": 549,"Seeding": 56},{"EventID": 403,"PlayerID": 128,"Seeding": 57},{"EventID": 403,"PlayerID": 35,"Seeding": 58},{"EventID": 403,"PlayerID": 37,"Seeding": 59},{"EventID": 403,"PlayerID": 8,"Seeding": 60},{"EventID": 403,"PlayerID": 115,"Seeding": 61},{"EventID": 403,"PlayerID": 50,"Seeding": 62},{"EventID": 403,"PlayerID": 507,"Seeding": 63},{"EventID": 403,"PlayerID": 76,"Seeding": 64},{"EventID": 403,"PlayerID": 131,"Seeding": 65},{"EventID": 403,"PlayerID": 45,"Seeding": 66},{"EventID": 403,"PlayerID": 906,"Seeding": 67},{"EventID": 403,"PlayerID": 592,"Seeding": 68},{"EventID": 403,"PlayerID": 218,"Seeding": 69},{"EventID": 403,"PlayerID": 87,"Seeding": 70},{"EventID": 403,"PlayerID": 81,"Seeding": 71},{"EventID": 403,"PlayerID": 169,"Seeding": 72},{"EventID": 403,"PlayerID": 497,"Seeding": 73},{"EventID": 403,"PlayerID": 49,"Seeding": 74},{"EventID": 403,"PlayerID": 34,"Seeding": 75},{"EventID": 403,"PlayerID": 894,"Seeding": 76},{"EventID": 403,"PlayerID": 6,"Seeding": 77},{"EventID": 403,"PlayerID": 1168,"Seeding": 78},{"EventID": 403,"PlayerID": 89,"Seeding": 79},{"EventID": 403,"PlayerID": 41,"Seeding": 80},{"EventID": 403,"PlayerID": 528,"Seeding": 81},{"EventID": 403,"PlayerID": 520,"Seeding": 82},{"EventID": 403,"PlayerID": 216,"Seeding": 83},{"EventID": 403,"PlayerID": 67,"Seeding": 84},{"EventID": 403,"PlayerID": 666,"Seeding": 85},{"EventID": 403,"PlayerID": 510,"Seeding": 86},{"EventID": 403,"PlayerID": 908,"Seeding": 87},{"EventID": 403,"PlayerID": 82,"Seeding": 88},{"EventID": 403,"PlayerID": 605,"Seeding": 89},{"EventID": 403,"PlayerID": 26,"Seeding": 90},{"EventID": 403,"PlayerID": 1044,"Seeding": 91},{"EventID": 403,"PlayerID": 534,"Seeding": 92},{"EventID": 403,"PlayerID": 193,"Seeding": 93},{"EventID": 403,"PlayerID": 3,"Seeding": 94},{"EventID": 403,"PlayerID": 14,"Seeding": 95},{"EventID": 403,"PlayerID": 23,"Seeding": 96},{"EventID": 403,"PlayerID": 32,"Seeding": 97},{"EventID": 403,"PlayerID": 120,"Seeding": 98},{"EventID": 403,"PlayerID": 151,"Seeding": 99},{"EventID": 403,"PlayerID": 269,"Seeding": 100},{"EventID": 403,"PlayerID": 448,"Seeding": 101},{"EventID": 403,"PlayerID": 521,"Seeding": 102},{"EventID": 403,"PlayerID": 523,"Seeding": 103},{"EventID": 403,"PlayerID": 552,"Seeding": 104},{"EventID": 403,"PlayerID": 620,"Seeding": 105},{"EventID": 403,"PlayerID": 621,"Seeding": 106},{"EventID": 403,"PlayerID": 898,"Seeding": 107},{"EventID": 403,"PlayerID": 917,"Seeding": 108}]
\ No newline at end of file