// Path: src/main/java/blue/lapis/common/command/CommandContext.java
// public interface CommandContext<S extends CommandSource> {
// 
//     /**
//      * @return the CommandSource which this command was issued from
//      */
//     S getSource();
// 
//     /**
//      * @return the entire line of text entered, except for the portion recognized as the command
//      */
//     public String getLine();
// 
//     /**
//      * @return the tokens in String format, as determined by the Tokenizer for this command
//      */
//     public ImmutableList<String> getTokens();
// 
//     /**
//      * Gets the specified typesafe argument. Throws {@link InvalidTokenException} if the argument is not of the
//      * expected type.
//      *
//      * @param clazz The expected class of the argument
//      * @param argNum The index of the argument. Note that this is the argument number, not the token number.
//      * @param <T> The expected class of the argument
//      * @return The argument if it exists, or null if the index is past the end of the list
//      */
//     @Nullable
//     public <T> T get(Class<T> clazz, int argNum);
// }
// 
// 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/token/TokenParserRegistry.java
// public class TokenParserRegistry {
// 
//     private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
//     private static final Map<Class<?>, TokenParser<?>> tokenParserMap = Maps.newHashMap();
// 
//     static {
//         register(Player.class, new PlayerTokenParser());
//         register(Integer.class, new IntegerTokenParser());
//         register(Boolean.class, new BooleanTokenParser());
//     }
// 
// 
//     @SuppressWarnings("unchecked")
//     @Nullable
//     public static <T> TokenParser<T> get(Class<T> clazz) {
//         TokenParser<T> t;
//         lock.readLock().lock();
//         {
//             t = (TokenParser<T>) tokenParserMap.get(clazz);
//         }
//         lock.readLock().unlock();
//         return t;
//     }
// 
//     public static <T> void register(Class<T> clazz, TokenParser<T> parser) {
//         lock.writeLock().lock();
//         {
//             tokenParserMap.put(clazz, parser);
//         }
//         lock.writeLock().unlock();
//     }
// }


import org.spongepowered.api.util.command.CommandSource;
import java.util.List;
import javax.annotation.Nullable;
import blue.lapis.common.command.CommandContext;
import blue.lapis.common.command.token.InvalidTokenException;
import blue.lapis.common.command.token.TokenParser;
import blue.lapis.common.command.token.TokenParserRegistry;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
/*
 * 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;





/**
 * Lapis implementation of {@link CommandContext}
 */
public class CommandContextImpl<S extends CommandSource> implements CommandContext<S> {

    private final S source;
    private String line = "";
    private ImmutableList<String> tokens = ImmutableList.of();
    private List<Object> args = Lists.newArrayList();

    /**
     * Create an empty context for a command to run in.
     *
     * @param source the Player, CommandBlock, or Console the command was run from
     */
    public CommandContextImpl(final S source) {
        this.source = source;
    }

    @Override
    public S getSource() {
        return source;
    }

    @Override
    public String getLine() {
        return line;
    }

    @Override
    public ImmutableList<String> getTokens() {
        return tokens;
    }

    @Override
    @Nullable
// Path: src/main/java/blue/lapis/common/command/CommandContext.java
// public interface CommandContext<S extends CommandSource> {
// 
//     /**
//      * @return the CommandSource which this command was issued from
//      */
//     S getSource();
// 
//     /**
//      * @return the entire line of text entered, except for the portion recognized as the command
//      */
//     public String getLine();
// 
//     /**
//      * @return the tokens in String format, as determined by the Tokenizer for this command
//      */
//     public ImmutableList<String> getTokens();
// 
//     /**
//      * Gets the specified typesafe argument. Throws {@link InvalidTokenException} if the argument is not of the
//      * expected type.
//      *
//      * @param clazz The expected class of the argument
//      * @param argNum The index of the argument. Note that this is the argument number, not the token number.
//      * @param <T> The expected class of the argument
//      * @return The argument if it exists, or null if the index is past the end of the list
//      */
//     @Nullable
//     public <T> T get(Class<T> clazz, int argNum);
// }
// 
// 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/token/TokenParserRegistry.java
// public class TokenParserRegistry {
// 
//     private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
//     private static final Map<Class<?>, TokenParser<?>> tokenParserMap = Maps.newHashMap();
// 
//     static {
//         register(Player.class, new PlayerTokenParser());
//         register(Integer.class, new IntegerTokenParser());
//         register(Boolean.class, new BooleanTokenParser());
//     }
// 
// 
//     @SuppressWarnings("unchecked")
//     @Nullable
//     public static <T> TokenParser<T> get(Class<T> clazz) {
//         TokenParser<T> t;
//         lock.readLock().lock();
//         {
//             t = (TokenParser<T>) tokenParserMap.get(clazz);
//         }
//         lock.readLock().unlock();
//         return t;
//     }
// 
//     public static <T> void register(Class<T> clazz, TokenParser<T> parser) {
//         lock.writeLock().lock();
//         {
//             tokenParserMap.put(clazz, parser);
//         }
//         lock.writeLock().unlock();
//     }
// }


// Path: src/main/java/blue/lapis/common/command/impl/CommandContextImpl.java
import org.spongepowered.api.util.command.CommandSource;
import java.util.List;
import javax.annotation.Nullable;
import blue.lapis.common.command.CommandContext;
import blue.lapis.common.command.token.InvalidTokenException;
import blue.lapis.common.command.token.TokenParser;
import blue.lapis.common.command.token.TokenParserRegistry;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

/*
 * 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;





/**
 * Lapis implementation of {@link CommandContext}
 */
public class CommandContextImpl<S extends CommandSource> implements CommandContext<S> {

    private final S source;
    private String line = "";
    private ImmutableList<String> tokens = ImmutableList.of();
    private List<Object> args = Lists.newArrayList();

    /**
     * Create an empty context for a command to run in.
     *
     * @param source the Player, CommandBlock, or Console the command was run from
     */
    public CommandContextImpl(final S source) {
        this.source = source;
    }

    @Override
    public S getSource() {
        return source;
    }

    @Override
    public String getLine() {
        return line;
    }

    @Override
    public ImmutableList<String> getTokens() {
        return tokens;
    }

    @Override
    @Nullable
    @SuppressWarnings("unchecked")