From: gotty Date: Wed, 12 Jul 2017 12:32:13 +0000 (+0000) Subject: [LIB-8] Add EventFormat to the Event entity X-Git-Url: https://git.hedgecode.org/?p=snooker-score-api.git;a=commitdiff_plain;h=09c7dd64d38ad87dee57bc8f8836777a7e6befd0;hp=c92a3316562db2708f3958dca79343d6a0ca29f3 [LIB-8] Add EventFormat to the Event entity git-svn-id: https://svn.hedgecode.org/lib/snooker-score-api/trunk@131 fb0bcced-7025-49ed-a12f-f98bce993226 --- diff --git a/src/main/java/org/hedgecode/snooker/api/Event.java b/src/main/java/org/hedgecode/snooker/api/Event.java index 45b50b5..b3fdb68 100644 --- a/src/main/java/org/hedgecode/snooker/api/Event.java +++ b/src/main/java/org/hedgecode/snooker/api/Event.java @@ -77,6 +77,8 @@ public interface Event extends IdEntity { int format(); + EventFormat formatType(); + String twitter(); String hashTag(); diff --git a/src/main/java/org/hedgecode/snooker/api/EventFormat.java b/src/main/java/org/hedgecode/snooker/api/EventFormat.java new file mode 100644 index 0000000..37cfdb8 --- /dev/null +++ b/src/main/java/org/hedgecode/snooker/api/EventFormat.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2017. 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; + +/** + * Formats of the Snooker's Event Entity. + * + * @author Dmitry Samoshin aka gotty + */ +public enum EventFormat { + + UNKNOWN ( 0, "Unknown" ), + CUP ( 1, "Cup" ), + ROUND ( 2, "Round-robin" ), + ROUND_CUP ( 3, "Round-robin followed by cup" ), + PYRAMID ( 4, "Pyramid" ); + + private int number; + private String desc; + + EventFormat(int number, String desc) { + this.number = number; + this.desc = desc; + } + + public int number() { + return number; + } + + public String desc() { + return desc; + } + + public static EventFormat byNumber(int number) { + for (EventFormat type : EventFormat.values()) { + if (type.number() == number) + return type; + } + return EventFormat.UNKNOWN; + } + +} diff --git a/src/main/java/org/hedgecode/snooker/json/JsonEvent.java b/src/main/java/org/hedgecode/snooker/json/JsonEvent.java index 348d1a5..0ba62ab 100644 --- a/src/main/java/org/hedgecode/snooker/json/JsonEvent.java +++ b/src/main/java/org/hedgecode/snooker/json/JsonEvent.java @@ -22,6 +22,7 @@ import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import org.hedgecode.snooker.api.Event; +import org.hedgecode.snooker.api.EventFormat; import org.hedgecode.snooker.api.Season; /** @@ -85,6 +86,8 @@ public class JsonEvent extends JsonIdEntity implements Event { private boolean team; @SerializedName("Format") private int format; + @Expose + private EventFormat formatType; @SerializedName("Twitter") private String twitter; @SerializedName("HashTag") @@ -259,6 +262,13 @@ public class JsonEvent extends JsonIdEntity implements Event { } @Override + public EventFormat formatType() { + if (formatType == null) + formatType = EventFormat.byNumber(format); + return formatType; + } + + @Override public String twitter() { return twitter; } diff --git a/src/test/java/org/hedgecode/snooker/json/JsonEventTest.java b/src/test/java/org/hedgecode/snooker/json/JsonEventTest.java index 0262013..bdbdf69 100644 --- a/src/test/java/org/hedgecode/snooker/json/JsonEventTest.java +++ b/src/test/java/org/hedgecode/snooker/json/JsonEventTest.java @@ -76,6 +76,7 @@ public class JsonEventTest extends AbstractJsonTest { assertEquals(expected.eventPredictionId(), actual.eventPredictionId()); assertEquals(expected.team(), actual.team()); assertEquals(expected.format(), actual.format()); + assertEquals(expected.formatType(), actual.formatType()); assertEquals(expected.twitter(), actual.twitter()); assertEquals(expected.hashTag(), actual.hashTag()); assertEquals(expected.conversionRate(), actual.conversionRate(), 0.001); diff --git a/src/test/resources/org/hedgecode/snooker/json/JsonEventTest.ser b/src/test/resources/org/hedgecode/snooker/json/JsonEventTest.ser index 3723494..356fb15 100644 Binary files a/src/test/resources/org/hedgecode/snooker/json/JsonEventTest.ser and b/src/test/resources/org/hedgecode/snooker/json/JsonEventTest.ser differ diff --git a/src/test/resources/org/hedgecode/snooker/json/JsonEventsTest.ser b/src/test/resources/org/hedgecode/snooker/json/JsonEventsTest.ser index 4877309..3d5f9b4 100644 Binary files a/src/test/resources/org/hedgecode/snooker/json/JsonEventsTest.ser and b/src/test/resources/org/hedgecode/snooker/json/JsonEventsTest.ser differ