// Path: src/main/java/blue/lapis/common/command/impl/BooleanTokenParser.java
// public class BooleanTokenParser implements TokenParser<Boolean> {
//     private static final ImmutableList<String> TRUE = ImmutableList.of("1", "true", "yes", "on");
//     private static final ImmutableList<String> FALSE = ImmutableList.of("0", "false", "no", "off");
// 
//     @Override
//     public Boolean parse(CommandSource source, String token) {
//         token = Parsing.toLowerCase(token.trim());
//         if (TRUE.contains(token)) return true;
//         if (FALSE.contains(token)) return false;
//         throw new InvalidTokenException(token, Boolean.class);
//     }
// 
//     @Override
//     public List<String> suggest(CommandSource source, String token) {
//         token = token.trim();
//         if (!token.isEmpty()) {
//             token = Parsing.toLowerCase(token);
// 
//             ArrayList<String> result = Lists.newArrayListWithCapacity(1);
// 
//             for (String bool : TRUE)
//                 if (bool.startsWith(token)) {
//                     result.add(bool);
//                 }
//             for (String bool : FALSE)
//                 if (bool.startsWith(token)) {
//                     result.add(bool);
//                 }
// 
//             if (!result.isEmpty())
//                 return ImmutableList.copyOf(result);
//         }
// 
//         return ImmutableList.of("true", "false");
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/impl/IntegerTokenParser.java
// 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 {
//                 //Parse it out into an integer and return it back. This trims off any garbage.
//                 return ImmutableList.of(Integer.valueOf(match).toString());
//             } catch (NumberFormatException e) {
//                 //The first character was a digit. We checked.
//                 //This code section is probably unreachable but I like to be prepared for the impossible.
//                 return ImmutableList.of("" + ch);
//             }
//         } else {
//             //This String is invalid, so suggest a number
//             return ImmutableList.of("1");
//         }
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/impl/PlayerTokenParser.java
// public class PlayerTokenParser implements TokenParser<Player> {
// 
//     @Override
//     public Player parse(final CommandSource source, final String token) {
//         Collection<Player> players = LapisCommonsPlugin.getGame().getServer().getOnlinePlayers();
// 
//         // TODO: strip off leading "p:" ?
// 
//         // attempt resolving full names
//         for (Player p : players) {
//             if (p.getName().equalsIgnoreCase(token))
//                 return p;
//         }
// 
//         // attempt partial names
//         for (Player p : players) {
//             if (Parsing.startsWithIgnoreCase(p.getName(), token))
//                 return p;
//         }
// 
//         throw new InvalidTokenException(token, Player.class);
//     }
// 
//     @Override
//     public List<String> suggest(final CommandSource source, final String partial) {
//         List<String> results = Lists.newArrayList();
//         Collection<Player> players = LapisCommonsPlugin.getGame().getServer().getOnlinePlayers();
// 
//         for (Player p : players) {
//             if (Parsing.startsWithIgnoreCase(p.getName(), partial))
//                 results.add(p.getName());
//         }
// 
//         return results;
//     }
// 
// }


import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.annotation.Nullable;
import blue.lapis.common.command.impl.BooleanTokenParser;
import blue.lapis.common.command.impl.IntegerTokenParser;
import blue.lapis.common.command.impl.PlayerTokenParser;
import com.google.common.collect.Maps;
import org.spongepowered.api.entity.player.Player;
import java.util.Map;
/*
 * 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.token;





/**
 * Thread-safe registry/factory for {@link TokenParser}s, which resolve Strings into typesafe game objects.
 */
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());
// Path: src/main/java/blue/lapis/common/command/impl/BooleanTokenParser.java
// public class BooleanTokenParser implements TokenParser<Boolean> {
//     private static final ImmutableList<String> TRUE = ImmutableList.of("1", "true", "yes", "on");
//     private static final ImmutableList<String> FALSE = ImmutableList.of("0", "false", "no", "off");
// 
//     @Override
//     public Boolean parse(CommandSource source, String token) {
//         token = Parsing.toLowerCase(token.trim());
//         if (TRUE.contains(token)) return true;
//         if (FALSE.contains(token)) return false;
//         throw new InvalidTokenException(token, Boolean.class);
//     }
// 
//     @Override
//     public List<String> suggest(CommandSource source, String token) {
//         token = token.trim();
//         if (!token.isEmpty()) {
//             token = Parsing.toLowerCase(token);
// 
//             ArrayList<String> result = Lists.newArrayListWithCapacity(1);
// 
//             for (String bool : TRUE)
//                 if (bool.startsWith(token)) {
//                     result.add(bool);
//                 }
//             for (String bool : FALSE)
//                 if (bool.startsWith(token)) {
//                     result.add(bool);
//                 }
// 
//             if (!result.isEmpty())
//                 return ImmutableList.copyOf(result);
//         }
// 
//         return ImmutableList.of("true", "false");
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/impl/IntegerTokenParser.java
// 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 {
//                 //Parse it out into an integer and return it back. This trims off any garbage.
//                 return ImmutableList.of(Integer.valueOf(match).toString());
//             } catch (NumberFormatException e) {
//                 //The first character was a digit. We checked.
//                 //This code section is probably unreachable but I like to be prepared for the impossible.
//                 return ImmutableList.of("" + ch);
//             }
//         } else {
//             //This String is invalid, so suggest a number
//             return ImmutableList.of("1");
//         }
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/impl/PlayerTokenParser.java
// public class PlayerTokenParser implements TokenParser<Player> {
// 
//     @Override
//     public Player parse(final CommandSource source, final String token) {
//         Collection<Player> players = LapisCommonsPlugin.getGame().getServer().getOnlinePlayers();
// 
//         // TODO: strip off leading "p:" ?
// 
//         // attempt resolving full names
//         for (Player p : players) {
//             if (p.getName().equalsIgnoreCase(token))
//                 return p;
//         }
// 
//         // attempt partial names
//         for (Player p : players) {
//             if (Parsing.startsWithIgnoreCase(p.getName(), token))
//                 return p;
//         }
// 
//         throw new InvalidTokenException(token, Player.class);
//     }
// 
//     @Override
//     public List<String> suggest(final CommandSource source, final String partial) {
//         List<String> results = Lists.newArrayList();
//         Collection<Player> players = LapisCommonsPlugin.getGame().getServer().getOnlinePlayers();
// 
//         for (Player p : players) {
//             if (Parsing.startsWithIgnoreCase(p.getName(), partial))
//                 results.add(p.getName());
//         }
// 
//         return results;
//     }
// 
// }


// Path: src/main/java/blue/lapis/common/command/token/TokenParserRegistry.java
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.annotation.Nullable;
import blue.lapis.common.command.impl.BooleanTokenParser;
import blue.lapis.common.command.impl.IntegerTokenParser;
import blue.lapis.common.command.impl.PlayerTokenParser;
import com.google.common.collect.Maps;
import org.spongepowered.api.entity.player.Player;
import java.util.Map;

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





/**
 * Thread-safe registry/factory for {@link TokenParser}s, which resolve Strings into typesafe game objects.
 */
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());