From 09c7dd64d38ad87dee57bc8f8836777a7e6befd0 Mon Sep 17 00:00:00 2001 From: gotty Date: Wed, 12 Jul 2017 12:32:13 +0000 Subject: [PATCH] [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 --- src/main/java/org/hedgecode/snooker/api/Event.java | 2 + .../org/hedgecode/snooker/api/EventFormat.java | 56 +++++++++++++++++++++ .../java/org/hedgecode/snooker/json/JsonEvent.java | 10 ++++ .../org/hedgecode/snooker/json/JsonEventTest.java | 1 + .../org/hedgecode/snooker/json/JsonEventTest.ser | Bin 1185 -> 1241 bytes .../org/hedgecode/snooker/json/JsonEventsTest.ser | Bin 25544 -> 25676 bytes 6 files changed, 69 insertions(+) create mode 100644 src/main/java/org/hedgecode/snooker/api/EventFormat.java 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 3723494f3e68c78fe2218ea1c974b7ec020b77bc..356fb15588794e7bf56dfb537646890ee12044bf 100644 GIT binary patch delta 79 zcmZ3;d6RR34!4cdgvsgiwjN<((A;Pq$H>Q(mS2>cSQ1iMkXpi^K6xXf0-GCHWb-7( hLPidUYZ{gdm@X@C=4R$*WGt90#^TG!J2{2L763N{7~}u| delta 51 zcmV-30L=f{384v)EDLV6vum=LP1Ik0&Nk5QiNJ4;;0}U?wgyy*lx+M`d=yv!7evT$n4)7`>dA7oia!->P6{7MAqFnnNefO%u)Yzs)o; zk>RU1ZQ0P`tKZ(f$|p((*-ObG6|CZaJZ&>0Hcn~s2c~_ahIP|FX4*kMqlA(BT{A)$ ziM&HB5-|;ua}iyyv_o4+DIS_Co)o}*qe!j-U{auuRp zEY(4Nq=_(9bPig!t8{0QU#^>OeA!=Jw4J%FV5k!VYOB z?1+(YXBdwWitC7_KL5t@{A^c0{l1Yn%5&t~6oIbW0)6p`rq`OxrR_dZJnWXm!!@~< zEfos|_9(wr5zqJW&fWy{t5vSz=4QJZFD7%7!<6y__i=W{d>4bBCl|rD@tMSFG-WXu zX7>s3>)ByouZ)D7YB3Zf;0I#to`m4oL@*{UXL&Mwnn)Y@|5{#s7<@iQ&3P!3f<21h zX%an;H#wNE<8p^o!K?`Oqy%!m68MgBb%3csnL0$d?DVrh9}?kCY7K4JQ&Bdk3gi3@ zb8~20?Vjh&fwm^VXqtoUZdkg6ha0x|5Tb*&7z$mISlH}FqXMi zAi<*}7mww?=!AGr7UgmCg?O4}Hdu0$aA!VF9P1Qk3&mZ}rao;8g85o5_nnu6nFjPZ zH1|x75clc{_Ydm%$HUHb>XU^Q)|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