Commits

DerFrZocker authored and md_5 committed 8523fa23ad1
#604: Add Contract annotation to ConfigurationSection
No tags

src/main/java/org/bukkit/configuration/ConfigurationSection.java

Modified
1 1 package org.bukkit.configuration;
2 2
3 3 import java.util.List;
4 4 import java.util.Map;
5 5 import java.util.Set;
6 6 import org.bukkit.Color;
7 7 import org.bukkit.Location;
8 8 import org.bukkit.OfflinePlayer;
9 9 import org.bukkit.configuration.serialization.ConfigurationSerializable;
10 10 import org.bukkit.inventory.ItemStack;
11 11 import org.bukkit.util.Vector;
12 +import org.jetbrains.annotations.Contract;
12 13 import org.jetbrains.annotations.NotNull;
13 14 import org.jetbrains.annotations.Nullable;
14 15
15 16 /**
16 17 * Represents a section of a {@link Configuration}
17 18 */
18 19 public interface ConfigurationSection {
19 20 /**
20 21 * Gets a set containing all keys in this section.
21 22 * <p>
173 174 * found.
174 175 * <p>
175 176 * If the Object does not exist then the specified default value will
176 177 * returned regardless of if a default has been identified in the root
177 178 * {@link Configuration}.
178 179 *
179 180 * @param path Path of the Object to get.
180 181 * @param def The default value to return if the path is not found.
181 182 * @return Requested Object.
182 183 */
184 + @Contract("_, !null -> !null")
183 185 @Nullable
184 186 public Object get(@NotNull String path, @Nullable Object def);
185 187
186 188 /**
187 189 * Sets the specified path to the given value.
188 190 * <p>
189 191 * If value is null, the entry will be removed. Any existing entry will be
190 192 * replaced, regardless of what the new value is.
191 193 * <p>
192 194 * Some implementations may have limitations on what you may store. See
247 249 * <p>
248 250 * If the String does not exist then the specified default value will
249 251 * returned regardless of if a default has been identified in the root
250 252 * {@link Configuration}.
251 253 *
252 254 * @param path Path of the String to get.
253 255 * @param def The default value to return if the path is not found or is
254 256 * not a String.
255 257 * @return Requested String.
256 258 */
259 + @Contract("_, !null -> !null")
257 260 @Nullable
258 261 public String getString(@NotNull String path, @Nullable String def);
259 262
260 263 /**
261 264 * Checks if the specified path is a String.
262 265 * <p>
263 266 * If the path exists but is not a String, this will return false. If the
264 267 * path does not exist, this will return false. If the path does not exist
265 268 * but a default value has been specified, this will check if that default
266 269 * value is a String and return appropriately.
449 452 * <p>
450 453 * If the List does not exist then the specified default value will
451 454 * returned regardless of if a default has been identified in the root
452 455 * {@link Configuration}.
453 456 *
454 457 * @param path Path of the List to get.
455 458 * @param def The default value to return if the path is not found or is
456 459 * not a List.
457 460 * @return Requested List.
458 461 */
462 + @Contract("_, !null -> !null")
459 463 @Nullable
460 464 public List<?> getList(@NotNull String path, @Nullable List<?> def);
461 465
462 466 /**
463 467 * Checks if the specified path is a List.
464 468 * <p>
465 469 * If the path exists but is not a List, this will return false. If the
466 470 * path does not exist, this will return false. If the path does not exist
467 471 * but a default value has been specified, this will check if that default
468 472 * value is a List and return appropriately.
670 674 * Boolean.class, def) is equivalent to {@link #getBoolean(String, boolean) #getBoolean(path,
671 675 * def)} for example.
672 676 *
673 677 * @param <T> the type of the requested object
674 678 * @param path the path to the object.
675 679 * @param clazz the type of the requested object
676 680 * @param def the default object to return if the object is not present at
677 681 * the path
678 682 * @return Requested object
679 683 */
684 + @Contract("_, _, !null -> !null")
680 685 @Nullable
681 686 public <T extends Object> T getObject(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def);
682 687
683 688 /**
684 689 * Gets the requested {@link ConfigurationSerializable} object at the given
685 690 * path.
686 691 *
687 692 * If the Object does not exist but a default value has been specified, this
688 693 * will return the default value. If the Object does not exist and no
689 694 * default value was specified, this will return null.
704 709 * returned regardless of if a default has been identified in the root
705 710 * {@link Configuration}.
706 711 *
707 712 * @param <T> the type of {@link ConfigurationSerializable}
708 713 * @param path the path to the object.
709 714 * @param clazz the type of {@link ConfigurationSerializable}
710 715 * @param def the default object to return if the object is not present at
711 716 * the path
712 717 * @return Requested {@link ConfigurationSerializable} object
713 718 */
719 + @Contract("_, _, !null -> !null")
714 720 @Nullable
715 721 public <T extends ConfigurationSerializable> T getSerializable(@NotNull String path, @NotNull Class<T> clazz, @Nullable T def);
716 722
717 723 /**
718 724 * Gets the requested Vector by path.
719 725 * <p>
720 726 * If the Vector does not exist but a default value has been specified,
721 727 * this will return the default value. If the Vector does not exist and no
722 728 * default value was specified, this will return null.
723 729 *
733 739 * <p>
734 740 * If the Vector does not exist then the specified default value will
735 741 * returned regardless of if a default has been identified in the root
736 742 * {@link Configuration}.
737 743 *
738 744 * @param path Path of the Vector to get.
739 745 * @param def The default value to return if the path is not found or is
740 746 * not a Vector.
741 747 * @return Requested Vector.
742 748 */
749 + @Contract("_, !null -> !null")
743 750 @Nullable
744 751 public Vector getVector(@NotNull String path, @Nullable Vector def);
745 752
746 753 /**
747 754 * Checks if the specified path is a Vector.
748 755 * <p>
749 756 * If the path exists but is not a Vector, this will return false. If the
750 757 * path does not exist, this will return false. If the path does not exist
751 758 * but a default value has been specified, this will check if that default
752 759 * value is a Vector and return appropriately.
776 783 * <p>
777 784 * If the OfflinePlayer does not exist then the specified default value
778 785 * will returned regardless of if a default has been identified in the
779 786 * root {@link Configuration}.
780 787 *
781 788 * @param path Path of the OfflinePlayer to get.
782 789 * @param def The default value to return if the path is not found or is
783 790 * not an OfflinePlayer.
784 791 * @return Requested OfflinePlayer.
785 792 */
793 + @Contract("_, !null -> !null")
786 794 @Nullable
787 795 public OfflinePlayer getOfflinePlayer(@NotNull String path, @Nullable OfflinePlayer def);
788 796
789 797 /**
790 798 * Checks if the specified path is an OfflinePlayer.
791 799 * <p>
792 800 * If the path exists but is not a OfflinePlayer, this will return false.
793 801 * If the path does not exist, this will return false. If the path does
794 802 * not exist but a default value has been specified, this will check if
795 803 * that default value is a OfflinePlayer and return appropriately.
818 826 * <p>
819 827 * If the ItemStack does not exist then the specified default value will
820 828 * returned regardless of if a default has been identified in the root
821 829 * {@link Configuration}.
822 830 *
823 831 * @param path Path of the ItemStack to get.
824 832 * @param def The default value to return if the path is not found or is
825 833 * not an ItemStack.
826 834 * @return Requested ItemStack.
827 835 */
836 + @Contract("_, !null -> !null")
828 837 @Nullable
829 838 public ItemStack getItemStack(@NotNull String path, @Nullable ItemStack def);
830 839
831 840 /**
832 841 * Checks if the specified path is an ItemStack.
833 842 * <p>
834 843 * If the path exists but is not a ItemStack, this will return false. If
835 844 * the path does not exist, this will return false. If the path does not
836 845 * exist but a default value has been specified, this will check if that
837 846 * default value is a ItemStack and return appropriately.
860 869 * <p>
861 870 * If the Color does not exist then the specified default value will
862 871 * returned regardless of if a default has been identified in the root
863 872 * {@link Configuration}.
864 873 *
865 874 * @param path Path of the Color to get.
866 875 * @param def The default value to return if the path is not found or is
867 876 * not a Color.
868 877 * @return Requested Color.
869 878 */
879 + @Contract("_, !null -> !null")
870 880 @Nullable
871 881 public Color getColor(@NotNull String path, @Nullable Color def);
872 882
873 883 /**
874 884 * Checks if the specified path is a Color.
875 885 * <p>
876 886 * If the path exists but is not a Color, this will return false. If the
877 887 * path does not exist, this will return false. If the path does not exist
878 888 * but a default value has been specified, this will check if that default
879 889 * value is a Color and return appropriately.
902 912 * <p>
903 913 * If the Location does not exist then the specified default value will
904 914 * returned regardless of if a default has been identified in the root
905 915 * {@link Configuration}.
906 916 *
907 917 * @param path Path of the Location to get.
908 918 * @param def The default value to return if the path is not found or is not
909 919 * a Location.
910 920 * @return Requested Location.
911 921 */
922 + @Contract("_, !null -> !null")
912 923 @Nullable
913 924 public Location getLocation(@NotNull String path, @Nullable Location def);
914 925
915 926 /**
916 927 * Checks if the specified path is a Location.
917 928 * <p>
918 929 * If the path exists but is not a Location, this will return false. If the
919 930 * path does not exist, this will return false. If the path does not exist
920 931 * but a default value has been specified, this will check if that default
921 932 * value is a Location and return appropriately.

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut