[LIB-8] Add EventFormat to the Event entity
authorgotty <gotty@fb0bcced-7025-49ed-a12f-f98bce993226>
Wed, 12 Jul 2017 12:32:13 +0000 (12:32 +0000)
committergotty <gotty@fb0bcced-7025-49ed-a12f-f98bce993226>
Wed, 12 Jul 2017 12:32:13 +0000 (12:32 +0000)
git-svn-id: https://svn.hedgecode.org/lib/snooker-score-api/trunk@131 fb0bcced-7025-49ed-a12f-f98bce993226

src/main/java/org/hedgecode/snooker/api/Event.java
src/main/java/org/hedgecode/snooker/api/EventFormat.java [new file with mode: 0644]
src/main/java/org/hedgecode/snooker/json/JsonEvent.java
src/test/java/org/hedgecode/snooker/json/JsonEventTest.java
src/test/resources/org/hedgecode/snooker/json/JsonEventTest.ser
src/test/resources/org/hedgecode/snooker/json/JsonEventsTest.ser

index 45b50b5..b3fdb68 100644 (file)
@@ -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 (file)
index 0000000..37cfdb8
--- /dev/null
@@ -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;
+    }
+
+}
index 348d1a5..0ba62ab 100644 (file)
@@ -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;
     }
index 0262013..bdbdf69 100644 (file)
@@ -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);
index 3723494..356fb15 100644 (file)
Binary files a/src/test/resources/org/hedgecode/snooker/json/JsonEventTest.ser and b/src/test/resources/org/hedgecode/snooker/json/JsonEventTest.ser differ
index 4877309..3d5f9b4 100644 (file)
Binary files a/src/test/resources/org/hedgecode/snooker/json/JsonEventsTest.ser and b/src/test/resources/org/hedgecode/snooker/json/JsonEventsTest.ser differ