SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.NoSuchElementException;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SerializableAs("Pattern")
|
||||
public class Pattern implements ConfigurationSerializable {
|
||||
@@ -23,7 +24,7 @@ public class Pattern implements ConfigurationSerializable {
|
||||
* @param color the pattern color
|
||||
* @param pattern the pattern type
|
||||
*/
|
||||
public Pattern(DyeColor color, PatternType pattern) {
|
||||
public Pattern(@NotNull DyeColor color, @NotNull PatternType pattern) {
|
||||
this.color = color;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
@@ -33,12 +34,12 @@ public class Pattern implements ConfigurationSerializable {
|
||||
*
|
||||
* @param map the map to deserialize from
|
||||
*/
|
||||
public Pattern(Map<String, Object> map) {
|
||||
public Pattern(@NotNull Map<String, Object> map) {
|
||||
color = DyeColor.legacyValueOf(getString(map, COLOR));
|
||||
pattern = PatternType.getByIdentifier(getString(map, PATTERN));
|
||||
}
|
||||
|
||||
private static String getString(Map<?, ?> map, Object key) {
|
||||
private static String getString(@NotNull Map<?, ?> map, @NotNull Object key) {
|
||||
Object str = map.get(key);
|
||||
if (str instanceof String) {
|
||||
return (String) str;
|
||||
@@ -46,6 +47,7 @@ public class Pattern implements ConfigurationSerializable {
|
||||
throw new NoSuchElementException(map + " does not contain " + key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
return ImmutableMap.<String, Object>of(
|
||||
@@ -59,6 +61,7 @@ public class Pattern implements ConfigurationSerializable {
|
||||
*
|
||||
* @return the color of the pattern
|
||||
*/
|
||||
@NotNull
|
||||
public DyeColor getColor() {
|
||||
return color;
|
||||
}
|
||||
@@ -68,6 +71,7 @@ public class Pattern implements ConfigurationSerializable {
|
||||
*
|
||||
* @return the pattern type
|
||||
*/
|
||||
@NotNull
|
||||
public PatternType getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.bukkit.block.banner;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -53,7 +57,7 @@ public enum PatternType {
|
||||
}
|
||||
}
|
||||
|
||||
private PatternType(String key) {
|
||||
private PatternType(@NotNull String key) {
|
||||
this.identifier = key;
|
||||
}
|
||||
|
||||
@@ -63,6 +67,7 @@ public enum PatternType {
|
||||
*
|
||||
* @return the pattern's identifier
|
||||
*/
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
@@ -74,7 +79,9 @@ public enum PatternType {
|
||||
* @param identifier the identifier
|
||||
* @return the matched pattern type or null
|
||||
*/
|
||||
public static PatternType getByIdentifier(String identifier) {
|
||||
@Contract("null -> null")
|
||||
@Nullable
|
||||
public static PatternType getByIdentifier(@Nullable String identifier) {
|
||||
return byString.get(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user