Skip to content

Commit a560b4e

Browse files
committed
Just actually use booleans in enum
1 parent 652c6ac commit a560b4e

File tree

5 files changed

+47
-166
lines changed

5 files changed

+47
-166
lines changed

core/src/main/java/org/botblock/javabotblockapi/core/BotBlockAPI.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,19 @@ public Builder(){}
8080
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
8181
* <ul>
8282
* <li>{@link java.lang.NullPointerException NullPointerException} - When the provided Token is empty.</li>
83-
* <li>{@link java.lang.IllegalStateException IllegalStateException} - When the provided Site doesn't support POST requests.</li>
8483
* </ul>
84+
*
85+
* @throws java.lang.IllegalStateException
86+
* When the provided site does not support POST requests.
8587
*
8688
* @return The Builder after the site and token were set. Useful for chaining.
8789
*
8890
* @since 2.1.0
8991
*/
9092
public Builder addAuthToken(@Nonnull Site site, @Nonnull String token){
9193
CheckUtil.notEmpty(token, "Token");
92-
CheckUtil.supportsPost(site);
94+
if(!site.supportsPost())
95+
throw new IllegalArgumentException(site.getSite() + " does not support POST requests!");
9396

9497
tokens.put(site.getSite(), token);
9598
return this;

core/src/main/java/org/botblock/javabotblockapi/core/CheckUtil.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818

1919
package org.botblock.javabotblockapi.core;
2020

21-
import org.botblock.javabotblockapi.core.annotations.Get;
22-
import org.botblock.javabotblockapi.core.annotations.Post;
23-
24-
import java.lang.reflect.Field;
2521
import java.util.Map;
2622

2723
/**
@@ -67,40 +63,4 @@ public static void condition(boolean expression, String message){
6763
if(expression)
6864
throw new IllegalStateException(message);
6965
}
70-
71-
/**
72-
* Will throw a {@link java.lang.IllegalStateException IllegalStateException} when the provided
73-
* {@link org.botblock.javabotblockapi.core.Site Site instance} does not have the
74-
* {@link org.botblock.javabotblockapi.core.annotations.Post @Post annotation}.
75-
*
76-
* @param site
77-
* The Site instance to check.
78-
*/
79-
public static void supportsPost(Site site){
80-
Field field = getField(site);
81-
82-
condition(field == null || !field.isAnnotationPresent(Post.class), site.getSite() + " does not support POST!");
83-
}
84-
85-
/**
86-
* Will throw a {@link java.lang.IllegalStateException IllegalStateException} when the provided
87-
* {@link org.botblock.javabotblockapi.core.Site Site instance} does not have the
88-
* {@link org.botblock.javabotblockapi.core.annotations.Get @Post annotation}.
89-
*
90-
* @param site
91-
* The Site instance to check.
92-
*/
93-
public static void supportsGet(Site site){
94-
Field field = getField(site);
95-
96-
condition(field == null || !field.isAnnotationPresent(Get.class), site.getSite() + " does not support GET!");
97-
}
98-
99-
private static Field getField(Site site){
100-
try{
101-
return site.getClass().getField(site.name());
102-
}catch(NoSuchFieldException ex){
103-
return null;
104-
}
105-
}
10666
}

core/src/main/java/org/botblock/javabotblockapi/core/Site.java

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
*/
1818
package org.botblock.javabotblockapi.core;
1919

20-
import org.botblock.javabotblockapi.core.annotations.Get;
21-
import org.botblock.javabotblockapi.core.annotations.Post;
22-
2320
/**
2421
* Enum class containing all sites currently supported by BotBlock.org.
2522
*
@@ -30,185 +27,164 @@ public enum Site {
3027
/**
3128
* <a href="https://arcane-center.xyz" target="_blank">arcane-center.xyz</a>
3229
*/
33-
@Post
34-
ARCANE_CENTER_XYZ("arcane-center.xyz"),
30+
ARCANE_CENTER_XYZ("arcane-center.xyz", true, true),
3531

3632
/**
3733
* <a href="https://blist.xyz" target="_blank">blist.xyz</a>
3834
*/
39-
@Post
40-
BLIST_XYZ("blist.xyz"),
35+
BLIST_XYZ("blist.xyz", true, true),
4136

4237
/**
4338
* <a href="https://botlist.space" target="_blank">botlist.space</a>
4439
*/
45-
@Post
46-
BOTLIST_SPACE("botlist.space"),
40+
BOTLIST_SPACE("botlist.space", true, true),
4741

4842
/**
4943
* <a href="https://botsdatabase.com" target="_blank">botsdatabase.com</a>
5044
*/
51-
@Post
52-
BOTSDATABASE_COM("botsdatabase.com"),
45+
BOTSDATABASE_COM("botsdatabase.com", true, true),
5346

5447
/**
5548
* <a href="https://bots.discordlabs.org" target="_blank">bots.discordlabs.org</a>
5649
*/
57-
@Post
58-
BOTS_DISCORDLABS_ORG("bots.discordlabs.org"),
50+
BOTS_DISCORDLABS_ORG("bots.discordlabs.org", true, true),
5951

6052
/**
6153
* <a href="https://botsfordiscord.com" target="_blank">botsfordiscord.com</a>
6254
*/
63-
@Post
64-
BOTSFORDISCORD_COM("botsfordiscord.com"),
55+
BOTSFORDISCORD_COM("botsfordiscord.com", true, true),
6556

6657
/**
6758
* <a href="https://bots.ondiscord.xyz" target="_blank">bots.ondiscord.xyz</a>
6859
*/
69-
@Post
70-
BOTS_ONDISCORD_XYZ("bots.ondiscord.xyz"),
60+
BOTS_ONDISCORD_XYZ("bots.ondiscord.xyz", true, true),
7161

7262
/**
7363
* <a href="https://dblista.pl" target="_blank">dblista.pl</a>
7464
*/
75-
@Post
76-
DBLISTA_PL("dblista.pl"),
65+
DBLISTA_PL("dblista.pl", true, true),
7766

7867
/**
7968
* <a href="https://discordapps.dev" target="_blank">discordapps.dev</a>
8069
*/
81-
@Post
82-
DISCORDAPPS_DEV("discordapps.dev"),
70+
DISCORDAPPS_DEV("discordapps.dev", true, true),
8371

8472
/**
8573
* <a href="https://discord.boats" target="_blank">discord.boats</a>
8674
*/
87-
@Post
88-
DISCORD_BOATS("discord.boats"),
75+
DISCORD_BOATS("discord.boats", true, true),
8976

9077
/**
9178
* <a href="https://discordbotdirectory.net" target="_blank">discordbotdirectory.net</a>
9279
*
9380
* @since 6.3.0
9481
*/
95-
@Get
96-
DISCORDBOTDIRECTORY_NET("discordbotdirectory.net"),
82+
DISCORDBOTDIRECTORY_NET("discordbotdirectory.net", true, false),
9783

9884
/**
9985
* <a href="https://discordbotlist.com" target="_blank">discordbotlist.com</a>
10086
*/
101-
@Post
102-
DISCORDBOTLIST_COM("discordbotlist.com"),
87+
DISCORDBOTLIST_COM("discordbotlist.com", true, true),
10388

10489
/**
10590
* <a href="https://discordbots.co" target="_blank">discordbots.co</a>
10691
*
10792
* @since 5.2.3
10893
*/
109-
@Post
110-
DISCORDBOTS_CO("discordbots.co"),
94+
DISCORDBOTS_CO("discordbots.co", true, true),
11195

11296
/**
11397
* <a href="https://discord.bots.gg" target="_blank">discord.bots.gg</a>
11498
*/
115-
@Post
116-
DISCORD_BOTS_GG("discord.bots.gg"),
99+
DISCORD_BOTS_GG("discord.bots.gg", true, true),
117100

118101
/**
119102
* <a href="https://discordbots.fun" target="_blank">discordbots.fun</a>
120103
*/
121-
@Post
122-
DISCORDBOTS_FUN("discordbots.fun"),
104+
DISCORDBOTS_FUN("discordbots.fun", true, true),
123105

124106
/**
125107
* <a href="https://discordextremelist.xyz" target="_blank">discordextremelist.xyz</a>
126108
*
127109
* @since 2.3.3
128110
*/
129-
@Post
130-
DISCORDEXTREMELIST_XYZ("discordextremelist.xyz"),
111+
DISCORDEXTREMELIST_XYZ("discordextremelist.xyz", true, true),
131112

132113
/**
133114
* <a href="https://discordlist.co" target="_blank">discordlist.co</a>
134115
*/
135-
@Post
136-
DISCORDLIST_CO("discordlist.co"),
116+
DISCORDLIST_CO("discordlist.co", true, true),
137117

138118
/**
139119
* <a href="https://discordlistology.com" target="_blank">discordlistology.com</a>
140120
*
141121
* @since 5.2.1
142122
*/
143-
@Post
144-
DISCORDLISTOLOGY_COM("discordlistology.com"),
123+
DISCORDLISTOLOGY_COM("discordlistology.com", true, true),
145124

146125
/**
147126
* <a href="https://disforge.com/bots" target="_blank">disforge.com</a>
148127
*
149128
* @since 6.2.2
150129
*/
151-
@Post
152-
DISFORGE_COM("disforge.com"),
130+
DISFORGE_COM("disforge.com", true, true),
153131

154132
/**
155133
* <a href="https://glennbotlist.xyz" target="_blank">glennbotlist.xyz</a>
156134
*/
157-
@Post
158-
GLENNBOTLIST_XYZ("glennbotlist.xyz"),
135+
GLENNBOTLIST_XYZ("glennbotlist.xyz", true, true),
159136

160137
/**
161138
* <a href="https://hydrogenbots.club" target="_blank">hydrogenbots.club</a>
162139
*
163140
* @since 6.2.1
164141
*/
165-
@Post
166-
HYDROGENBOTS_CLUB("hydrogenbots.club"),
142+
HYDROGENBOTS_CLUB("hydrogenbots.club", true, true),
167143

168144
/**
169145
* <a href="https://mythicalbots.xyz" target="_blank">mythicalbots.xyz</a>
170146
*/
171-
@Post
172-
MYTHICALBOTS_XYZ("mythicalbots.xyz"),
147+
MYTHICALBOTS_XYZ("mythicalbots.xyz", true, true),
173148

174149
/**
175150
* <a href="https://space-bot-list.xyz" target="_blank">space-bot-list.xyz</a>
176151
*/
177-
@Post
178-
SPACE_BOT_LIST_XYZ("space-bot-list.xyz"),
152+
SPACE_BOT_LIST_XYZ("space-bot-list.xyz", true, true),
179153

180154
/**
181155
* <a href="https://topcord.xyz" target="_blank">topcord.xyz</a>
182156
*/
183-
@Post
184-
TOPCORD_XYZ("topcord.xyz"),
157+
TOPCORD_XYZ("topcord.xyz", true, true),
185158

186159
/**
187160
* <a href="https://voidbots.net" target="_blank">voidbots.net</a>
188161
*
189162
* @since 6.3.0
190163
*/
191-
@Post
192-
VOIDBOTS_NET("voidbots.net"),
164+
VOIDBOTS_NET("voidbots.net", true, true),
193165

194166
/**
195167
* <a href="https://wonderbotlist.com" target="_blank">wonderbotlist.com</a>
196168
*/
197-
@Post
198-
WONDERBOTLIST_COM("wonderbotlist.com"),
169+
WONDERBOTLIST_COM("wonderbotlist.com", true, true),
199170

200171
/**
201172
* <a href="https://yabl.xyz" target="_blank">yabl.xyz</a>
202173
*
203174
* @since 2.1.1
204175
*/
205-
@Post
206-
YABL_XYZ("yabl.xyz");
176+
YABL_XYZ("yabl.xyz", true, true);
207177

208178
private final String site;
209179

210-
Site(String site){
180+
private final boolean hasGet;
181+
private final boolean hasPost;
182+
183+
Site(String site, boolean hasGet, boolean hasPost){
211184
this.site = site;
185+
186+
this.hasGet = hasGet;
187+
this.hasPost = hasPost;
212188
}
213189

214190
/**
@@ -219,4 +195,12 @@ public enum Site {
219195
public String getSite(){
220196
return this.site;
221197
}
198+
199+
public boolean supportsGet(){
200+
return hasGet;
201+
}
202+
203+
public boolean supportsPost(){
204+
return hasPost;
205+
}
222206
}

core/src/main/java/org/botblock/javabotblockapi/core/annotations/Get.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

core/src/main/java/org/botblock/javabotblockapi/core/annotations/Post.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)