Skip to content

Commit 280767f

Browse files
authored
Merge pull request #174 from botblock/feature/annotage-method-types
Add values for if Site supports GET and POST
2 parents 3938efb + 6daa1be commit 280767f

File tree

20 files changed

+523
-277
lines changed

20 files changed

+523
-277
lines changed

.github/CONTRIBUTING.md

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,41 +91,63 @@ In most cases will you only update `{build}` and nothing else. If you're unsure
9191
Please **do not change already existing since annotations**. This also includes adding ones to already existing methods/classes.
9292

9393
### Deprecated methods
94+
> Please also see the [Deprecation Policy](#deprecation-policy) about how to handle deprecations
95+
9496
If you're deprecating a method will you need to add the `@Deprecated` annotation and also include a `@deprecated` tag in the comment explain why it was deprecated and mention possible replacements.
9597

96-
You also need to add the `@DeprecatedSince` annotation to indicate since when a method is deprecated. This annotation has a required version field and an optional replacements field.
97-
You may also add the `@PlannedRemoval` annotation if the object is planned to be removed in a future release. This annotation has a required version field, which indicate in what version the object will be removed.
98-
The specified version has to be at least 2 versions away from the one that the object got deprecated in (i.e. deprecating a method in `5.2.0` will require you to set the version to at least `5.2.2` in the `PlannedRemoval` annotation).
98+
You also need to add the `@DeprecatedSince` annotation to indicate since when a method is deprecated. This annotation has the fields `major`, `minor`, `patch` and `replacement` from which the last one is optional.
99+
You may also add the `@PlannedRemoval` annotation if the object is planned to be removed in a future release. This annotation has a `major`, `minor` and `patch` field to mark the version for when the object is removed.
100+
101+
### CheckUtil
102+
JavaBotBlockAPI has a CheckUtil with some static void methods for checking various things such as if a String is empty.
103+
104+
When using any methods of the CheckUtil should you add the following text to the Javadoc comment as its own Paragraph:
105+
```java
106+
/**
107+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
108+
* <ul>
109+
* <li>{@link java.lang.NullPointerException NullPointerException} - Mention the cause here.</li>
110+
* <li>{@link java.lang.IllegalStateException IllegalStateException} - Mention the cause here.</li>
111+
* </ul>
112+
*/
113+
```
114+
115+
The CheckUtil has the following methods which can have the mentioned Excpetions:
116+
117+
- `ChekUtil#notEmpty(String value, String name)` - Checks the String "value" is empty and throws a NullPointerException with the message `name + " may not be empty."` in such a case.
118+
- `CheckUtil#notEmpty(Map<?, ?> value, String name)` - Checks if the Map "value" is empty and throws a NullPointerException with the message `name + " may not be empty."` in such a case.
119+
- `CheckUtil#condition(boolean expression, String message)` - Checks if the boolean "expression" returns true and throws a IllegalStateException with the message `message`.
99120

100121
### Other Styling
101122
Please make sure that all text is on the same vertical line (block).
102123
This means that when f.e. a `@return` is used, that you have to use two spaces after `@param` instead of one.
103124

104125
### Order of the parts
105-
Here is an example of the different parts being used:
126+
Here is an example of using the different parts together:
106127
```java
107128
/**
108129
* Adds "Bar" to the provided text.
109130
* <br>Will throw an error when not providing text.
131+
*
132+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
133+
* <ul>
134+
* <li>{@link java.lang.NullPointerException NullPointerException} - When foo is empty.</li>
135+
* </ul>
110136
*
111137
* @param foo
112138
* The text that should get "Bar" added to it.
113139
*
114140
* @return The provided String with "Bar" added to it.
115141
*
116-
* @throws IllegalArgumentException
117-
* When the provided String is empty/null.
118-
*
119-
* @since v1.0.0
142+
* @since 1.0.0
120143
*
121144
* @deprecated Use {@link #getFooBar() getFooBar()} instead.
122145
*/
123146
@Deprecated
124-
@DeprecatedSince(version = "1.0.0", replacements = {"#getFooBar"}) // If you deprecate a method, add this one too.
125-
@PlannedRemoval(version = "1.0.2") // When the objects gets removed in the future, add this annotation.
126-
public String getFooBar(String foo) throws IllegalArgumentException{
127-
if(foo.isEmpty())
128-
throw new IllegalArgumentException("foo may not be empty");
147+
@DeprecatedSince(major = 1, minor = 0, patch = 0, replacements = {"#getFooBar"}) // If you deprecate a method, add this one too.
148+
@PlannedRemoval(major = 1, minor = 0, patch = 2)
149+
public String getFooBar(@Nonnull String foo){
150+
CheckUtil.notEmpty(foo, "Foo");
129151

130152
return foo + "Bar";
131153
}
@@ -135,14 +157,23 @@ public String getFooBar(String foo) throws IllegalArgumentException{
135157
*
136158
* @return {@code "foobar"}
137159
*
138-
* @since v1.0.1
160+
* @since 1.0.1
139161
*/
140162
public String getFooBar(){
141163
return "foobar";
142164
}
143165
```
144166

167+
## Deprecation Policy
168+
To not fully break the Wrapper on each release do we follow a general deprecation policy, to give people time to move to any replacement method, if available.
169+
170+
If possible should always a replacement method, field or other object be provided when deprecating an object.
171+
Any deprecated method is also planned for removal which is indicated by the `@PlannedRemoval` annotation. The version you define there has to be at least two patch-versions from the one the object became deprecated.
172+
This means that deprecating a method in `6.2.0` results in the major, minor and patch version of the annotation to display `6`, `2` and `2` respectively.
173+
174+
At **no point** should an object just be removed. We always mark it as deprecated first and give the aforementioned minimal delay for people to update, before removing it completely.
175+
145176
## [Code of Conduct]
146177
We want to give everyone a chance to contribute to the project.
147-
So please keep your comments and messages nice. Every message that is considered rasist, insulting or similar will be removed.
178+
So please keep your comments and messages nice. Every message that is considered racist, insulting or similar will be removed.
148179
If you continue to send those messages will we permanently remove you from this repository.

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins{
99
id 'net.kyori.blossom' version '1.1.0'
1010
}
1111

12-
def ver = new Version(major: 6, minor: 2, patch: 2)
12+
def ver = new Version(major: 6, minor: 3, patch: 0)
1313

1414
allprojects {
1515
apply plugin: 'com.jfrog.bintray'
@@ -26,6 +26,7 @@ allprojects {
2626
api group: 'org.json', name: 'json', version: '20200518'
2727
api group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '2.8.0'
2828
api group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
29+
api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
2930

3031
artifactId = (rootProject == project? project.name : "$rootProject.name-$project.name").toLowerCase()
3132
moduleName = "${group}.javabotblockapi${rootProject == project? "" : ".${project.name.toLowerCase()}"}"

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ public class BotBlockAPI{
3737
private final int updateDelay;
3838

3939
private BotBlockAPI(@Nonnull Map<String, String> tokens, int updateDelay){
40-
if(tokens.isEmpty())
41-
throw new NullPointerException("Tokens may not be empty.");
42-
43-
if(updateDelay < 2)
44-
throw new IllegalArgumentException("UpdateDelay may not be less than 2.");
40+
CheckUtil.notEmpty(tokens, "Tokens");
41+
CheckUtil.condition(updateDelay < 2, "UpdateDelay may not be less than 2");
4542

4643
this.tokens = tokens;
4744
this.updateDelay = updateDelay;
@@ -68,26 +65,30 @@ public static class Builder{
6865
public Builder(){}
6966

7067
/**
71-
* Adds the provided {@link org.botblock.javabotblockapi.core.Site Site name} and token to the Map.
68+
* Adds the provided {@link SiteOld Site name} and token to the Map.
7269
* <br>Entries with the same key will be overwritten.
7370
*
7471
* @param site
75-
* The {@link org.botblock.javabotblockapi.core.Site Site} to get the name from.
72+
* The {@link Site Site} to get the name from.
7673
* @param token
7774
* The API token from the corresponding bot list. May not be null or empty.
7875
* <br>You may receive the API token from the bot list.
7976
*
80-
* @throws java.lang.NullPointerException
81-
* When the provided token is empty ({@code ""}).
77+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
78+
* <ul>
79+
* <li>{@link java.lang.NullPointerException NullPointerException} - When the provided Token is empty.</li>
80+
* <li>{@link java.lang.IllegalStateException IllegalStateException} - When the provided Site doesn't support POST requests.</li>
81+
* </ul>
8282
*
8383
* @return The Builder after the site and token were set. Useful for chaining.
8484
*
8585
* @since 2.1.0
8686
*/
8787
public Builder addAuthToken(@Nonnull Site site, @Nonnull String token){
8888
CheckUtil.notEmpty(token, "Token");
89+
CheckUtil.condition(!site.supportsPost(), site.getName() + " does not support POST requests!");
8990

90-
tokens.put(site.getSite(), token);
91+
tokens.put(site.getName(), token);
9192
return this;
9293
}
9394

@@ -102,8 +103,10 @@ public Builder addAuthToken(@Nonnull Site site, @Nonnull String token){
102103
* The API token from the corresponding bot list. May not be null or empty.
103104
* <br>You may receive the API token from the bot list.
104105
*
105-
* @throws java.lang.NullPointerException
106-
* When either the site or token are empty ({@code ""}).
106+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
107+
* <ul>
108+
* <li>{@link java.lang.NullPointerException NullPointerException} - When the provided Site or Token is empty.</li>
109+
* </ul>
107110
*
108111
* @return The Builder after the site and token were set. Useful for chaining.
109112
*/
@@ -122,8 +125,10 @@ public Builder addAuthToken(@Nonnull String site, @Nonnull String token){
122125
* @param tokens
123126
* The Map that should be used. May not be null.
124127
*
125-
* @throws java.lang.NullPointerException
126-
* When the provided Map is empty.
128+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
129+
* <ul>
130+
* <li>{@link java.lang.NullPointerException NullPointerException} - When the provided Token is empty.</li>
131+
* </ul>
127132
*
128133
* @return The Builder after the Map was set. Useful for chaining.
129134
*/
@@ -141,8 +146,10 @@ public Builder setAuthTokens(@Nonnull Map<String, String> tokens){
141146
* @param updateDelay
142147
* The update interval in minutes that should be used. This can't be less than 2.
143148
*
144-
* @throws java.lang.IllegalStateException
145-
* When the updateInterval is less than 2.
149+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
150+
* <ul>
151+
* <li>{@link java.lang.IllegalStateException IllegalStateException} - When the provided interval is less than 2.</li>
152+
* </ul>
146153
*
147154
* @return The Builder after the updateInterval was set. Useful for chaining.
148155
*/
@@ -156,8 +163,10 @@ public Builder setUpdateDelay(@Nonnull Integer updateDelay){
156163
/**
157164
* Builds the instance of {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI}.
158165
*
159-
* @throws java.lang.NullPointerException
160-
* When the Tokens Map is empty.
166+
* <p>Following Exceptions can be thrown from the {@link org.botblock.javabotblockapi.core.CheckUtil CheckUtil}:
167+
* <ul>
168+
* <li>{@link java.lang.NullPointerException NullPointerException} - When the Tokens Map is empty.</li>
169+
* </ul>
161170
*
162171
* @return The built, usable {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI}.
163172
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.Map;
2222

2323
/**
24-
* Util class to perform basic checks.
24+
* Utility class to perform basic checks.
2525
*/
2626
public class CheckUtil{
2727

0 commit comments

Comments
 (0)