// Path: src/main/java/blue/lapis/common/command/token/InvalidTokenException.java
// public class InvalidTokenException extends RuntimeException {
// 
//     private String token;
//     private Class<?> expectedType;
// 
//     public InvalidTokenException(String token, Class<?> expectedType) {
//         this.token = token;
//         this.expectedType = expectedType;
//     }
// 
//     /**
//      * @return the token that the TokenParser attempted to resolve
//      */
//     public String getToken() {
//         return token;
//     }
// 
//     /**
//      * @return the Class of the object which the TokenParser creates
//      */
//     public Class<?> getExpectedType() {
//         return expectedType;
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/TokenParser.java
// public interface TokenParser<T> {
// 
//     /**
//      * Parse the provided parser and return a typesafe object for it.
//      *
//      * @param source the Player, console, or command block which initiated this object resolution
//      * @param token the token to be resolved into an object of type {@code T}
//      * @return an object of type T which corresponds to the String entered
//      *
//      * @throws InvalidTokenException if the String does not appear to match any object
//      */
//     T parse(CommandSource source, String token);
// 
//     /**
//      * Get tab-complete suggestions for this parser
//      *
//      * @param source The Player, CommandBlock, etc. responsible for this token
//      * @param token The token to generate tab-complete suggestions for
//      * @return a List of possible completions, or an empty List if none are available
//      */
//     List<String> suggest(CommandSource source, String token);
// }


import blue.lapis.common.command.token.InvalidTokenException;
import blue.lapis.common.command.token.TokenParser;
import com.google.common.collect.ImmutableList;
import org.spongepowered.api.util.command.CommandSource;
import java.util.List;
/*
 * LapisCommons
 * Copyright (c) 2014, Lapis <https://github.com/LapisBlue>
 *
 * 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 blue.lapis.common.command.impl;




/**
 * Converts tokens into Integers, much like the name would suggest.
 */
public class IntegerTokenParser implements TokenParser<Integer> {
    @Override
    public Integer parse(CommandSource source, String token) {
        try {
            return Integer.valueOf(token.trim());
        } catch (NumberFormatException e) {
            throw new InvalidTokenException(token, Integer.class);
        }
    }

    @Override
    public List<String> suggest(CommandSource source, String token) {
        String match = token.trim();
        if (match.length() == 0) return ImmutableList.of("1");
        char ch = match.charAt(0);

        if (Character.isDigit(ch)) {
// Path: src/main/java/blue/lapis/common/command/token/InvalidTokenException.java
// public class InvalidTokenException extends RuntimeException {
// 
//     private String token;
//     private Class<?> expectedType;
// 
//     public InvalidTokenException(String token, Class<?> expectedType) {
//         this.token = token;
//         this.expectedType = expectedType;
//     }
// 
//     /**
//      * @return the token that the TokenParser attempted to resolve
//      */
//     public String getToken() {
//         return token;
//     }
// 
//     /**
//      * @return the Class of the object which the TokenParser creates
//      */
//     public Class<?> getExpectedType() {
//         return expectedType;
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/TokenParser.java
// public interface TokenParser<T> {
// 
//     /**
//      * Parse the provided parser and return a typesafe object for it.
//      *
//      * @param source the Player, console, or command block which initiated this object resolution
//      * @param token the token to be resolved into an object of type {@code T}
//      * @return an object of type T which corresponds to the String entered
//      *
//      * @throws InvalidTokenException if the String does not appear to match any object
//      */
//     T parse(CommandSource source, String token);
// 
//     /**
//      * Get tab-complete suggestions for this parser
//      *
//      * @param source The Player, CommandBlock, etc. responsible for this token
//      * @param token The token to generate tab-complete suggestions for
//      * @return a List of possible completions, or an empty List if none are available
//      */
//     List<String> suggest(CommandSource source, String token);
// }


// Path: src/main/java/blue/lapis/common/command/impl/IntegerTokenParser.java
import blue.lapis.common.command.token.InvalidTokenException;
import blue.lapis.common.command.token.TokenParser;
import com.google.common.collect.ImmutableList;
import org.spongepowered.api.util.command.CommandSource;
import java.util.List;

/*
 * LapisCommons
 * Copyright (c) 2014, Lapis <https://github.com/LapisBlue>
 *
 * 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 blue.lapis.common.command.impl;




/**
 * Converts tokens into Integers, much like the name would suggest.
 */
public class IntegerTokenParser implements TokenParser<Integer> {
    @Override
    public Integer parse(CommandSource source, String token) {
        try {
            return Integer.valueOf(token.trim());
        } catch (NumberFormatException e) {
            throw new InvalidTokenException(token, Integer.class);
        }
    }

    @Override
    public List<String> suggest(CommandSource source, String token) {
        String match = token.trim();
        if (match.length() == 0) return ImmutableList.of("1");
        char ch = match.charAt(0);

        if (Character.isDigit(ch)) {
            try {