Java tutorial
/* * Copyright (c) 2016 Lucko (Luck) <luck@lucko.me> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package me.lucko.luckperms.common.api; import lombok.experimental.UtilityClass; import com.google.common.base.Preconditions; import me.lucko.luckperms.api.Group; import me.lucko.luckperms.api.Track; import me.lucko.luckperms.api.User; import me.lucko.luckperms.common.api.delegates.GroupDelegate; import me.lucko.luckperms.common.api.delegates.TrackDelegate; import me.lucko.luckperms.common.api.delegates.UserDelegate; import me.lucko.luckperms.common.utils.ArgumentChecker; @UtilityClass public class ApiUtils { public static void checkUser(User user) { Preconditions.checkState(user instanceof UserDelegate, "User instance cannot be handled by this implementation."); } public static void checkGroup(Group group) { Preconditions.checkState(group instanceof GroupDelegate, "Group instance cannot be handled by this implementation."); } public static void checkTrack(Track track) { Preconditions.checkState(track instanceof TrackDelegate, "Track instance cannot be handled by this implementation."); } public static String checkUsername(String s) { Preconditions.checkArgument(!ArgumentChecker.checkUsername(s), "Invalid username entry '" + s + "'. Usernames must be less than 16 chars and only contain 'a-z A-Z 1-9 _'."); return s; } public static String checkName(String s) { Preconditions.checkArgument(!ArgumentChecker.checkName(s), "Invalid name entry '" + s + "'. Names must be less than 37 chars and only contain 'a-z A-Z 1-9'."); return s.toLowerCase(); } public static long checkTime(long l) { Preconditions.checkArgument(!ArgumentChecker.checkTime(l), "Unix time '" + l + "' is invalid, as it has already passed."); return l; } }