Example usage for org.apache.commons.lang StringUtils startsWithIgnoreCase

List of usage examples for org.apache.commons.lang StringUtils startsWithIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils startsWithIgnoreCase.

Prototype

public static boolean startsWithIgnoreCase(String str, String prefix) 

Source Link

Document

Case insensitive check if a String starts with a specified prefix.

Usage

From source file:raptor.alias.RemoveTagAlias.java

@Override
public RaptorAliasResult apply(ChatConsoleController controller, String command) {
    if (StringUtils.startsWithIgnoreCase(command, "-tag")) {
        RaptorStringTokenizer tok = new RaptorStringTokenizer(command, " ", true);
        tok.nextToken();/* www  .j  ava  2s. com*/
        String tag = tok.nextToken();
        String user = tok.nextToken();

        if (StringUtils.isBlank(tag) || StringUtils.isBlank(user)) {
            return new RaptorAliasResult(null, "Invalid command: " + command + "\n" + getUsage());

        } else {
            UserTagService.getInstance().clearTag(tag, user);
            return new RaptorAliasResult(null, "Removed tag " + tag + " from user " + user);
        }
    } else {
        return null;
    }
}

From source file:raptor.alias.ShowTellsAlias.java

@Override
public RaptorAliasResult apply(final ChatConsoleController controller, String command) {
    command = command.trim();/*from   w  ww . j  a  v a  2  s  .  c  o  m*/
    if (StringUtils.startsWith(command, "=tells")) {

        final String whatsLeft = command.length() == 6 ? "" : command.substring(7).trim();

        if (whatsLeft.contains(" ")) {
            return new RaptorAliasResult(null, "Invalid command: " + command + ".\n" + getUsage());
        } else if (StringUtils.isBlank(whatsLeft)) {
            ThreadService.getInstance().run(new Runnable() {
                public void run() {
                    final StringBuilder builder = new StringBuilder(5000);
                    controller.getConnector().getChatService().getChatLogger()
                            .parseFile(new ChatEventParseListener() {
                                public boolean onNewEventParsed(ChatEvent event) {
                                    if (event.getType() == ChatType.TELL) {
                                        builder.append(FORMAT.format(new Date(event.getTime())))
                                                .append(event.getMessage().trim()).append("\n");
                                    }
                                    return true;
                                }

                                public void onParseCompleted() {
                                    Raptor.getInstance().getDisplay()
                                            .asyncExec(new RaptorRunnable(controller.getConnector()) {
                                                @Override
                                                public void execute() {
                                                    controller.onAppendChatEventToInputText(new ChatEvent(null,
                                                            ChatType.INTERNAL,
                                                            "All direct tells sent since you logged in:\n"
                                                                    + builder));
                                                }
                                            });
                                }
                            });

                }
            });
            return new RaptorAliasResult(null, "Your request is being processed. This may take a moment");

        } else if (NumberUtils.isDigits(whatsLeft)) {
            ThreadService.getInstance().run(new Runnable() {
                public void run() {
                    final StringBuilder builder = new StringBuilder(5000);
                    controller.getConnector().getChatService().getChatLogger()
                            .parseFile(new ChatEventParseListener() {
                                public boolean onNewEventParsed(ChatEvent event) {
                                    if (event.getType() == ChatType.CHANNEL_TELL
                                            && StringUtils.equals(event.getChannel(), whatsLeft)) {
                                        builder.append(FORMAT.format(new Date(event.getTime())))
                                                .append(event.getMessage().trim()).append("\n");
                                    }
                                    return true;
                                }

                                public void onParseCompleted() {
                                    Raptor.getInstance().getDisplay().asyncExec(new Runnable() {

                                        public void run() {
                                            controller.onAppendChatEventToInputText(
                                                    new ChatEvent(null, ChatType.INTERNAL, "All " + whatsLeft
                                                            + " tells sent since you logged in:\n" + builder));
                                        }
                                    });
                                }
                            });

                }
            });
            return new RaptorAliasResult(null, "Your request is being processed. This may take a moment");
        } else {
            ThreadService.getInstance().run(new Runnable() {
                public void run() {
                    final StringBuilder builder = new StringBuilder(5000);
                    controller.getConnector().getChatService().getChatLogger()
                            .parseFile(new ChatEventParseListener() {
                                public boolean onNewEventParsed(ChatEvent event) {
                                    if (event.getType() == ChatType.TELL
                                            && StringUtils.startsWithIgnoreCase(event.getSource(), whatsLeft)) {
                                        builder.append(FORMAT.format(new Date(event.getTime())))
                                                .append(event.getMessage().trim()).append("\n");
                                    }
                                    return true;
                                }

                                public void onParseCompleted() {
                                    Raptor.getInstance().getDisplay()
                                            .asyncExec(new RaptorRunnable(controller.getConnector()) {
                                                @Override
                                                public void execute() {
                                                    controller.onAppendChatEventToInputText(new ChatEvent(null,
                                                            ChatType.INTERNAL,
                                                            "All " + whatsLeft
                                                                    + " tells sent since you logged in:\n"
                                                                    + builder));
                                                }
                                            });
                                }
                            });

                }
            });
            return new RaptorAliasResult(null, "Your request is being processed. This may take a moment");
        }
    }
    return null;
}

From source file:raptor.chess.pgn.PgnUtils.java

/**
 * Returns the approximate number of games in the specified file.
 *///ww  w  .  ja  v  a 2 s.  com
public static int getApproximateGameCount(String file) {
    int result = 0;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(file));
        String currentLine = null;
        while ((currentLine = reader.readLine()) != null) {
            if (StringUtils.startsWithIgnoreCase(currentLine, "[Event")) {
                result++;
            }
        }
    } catch (IOException ioe) {
        LOG.error("Error reading game count" + file, ioe);
    } finally {
        try {
            reader.close();
        } catch (IOException ioe) {
        }
    }
    return result;
}

From source file:raptor.connector.ics.IcsConnector.java

public boolean isLikelyPartnerTell(String outboundMessage) {
    return StringUtils.startsWithIgnoreCase(outboundMessage, "pt");
}

From source file:stormy.pythian.features.component.steps.PropertyTypeConverter.java

public static PropertyTypeConverter from(String type) {
    if (StringUtils.startsWithIgnoreCase(type, ENUM.name() + ":")) {
        return ENUM;
    }//from w w w.j  a v  a 2s. c  o  m

    for (PropertyTypeConverter converter : PropertyTypeConverter.values()) {
        if (StringUtils.equalsIgnoreCase(converter.name(), type)) {
            return converter;
        }
    }
    throw new IllegalArgumentException("No type converter found for " + type);
}

From source file:sv1djg.hamutils.dxcc.DXCCEntitiesReader.java

private void updateDXCCEntitiesWithMostWanted() {

    int dxccListCount = _dxccList.size();
    int wantedDxccCount = _mostWantedList.size();
    int matchedWantedDxccCount = 0;

    //System.out.println("Matching DXCC list to most wanted...PASS 1");

    // iterate once and match the most common ones
    for (DXCCEntity dxccEntity : _dxccList) {
        boolean foundMatch = false;
        for (DXCCEntity wantedEntity : _mostWantedList) {
            if (wantedEntity.prefix.equalsIgnoreCase(dxccEntity.prefix)) {
                dxccEntity.rankingInMostWanted = wantedEntity.rankingInMostWanted;

                matchedWantedDxccCount++;
                foundMatch = true;/*from   ww  w  .  j  a v  a  2 s  . c o m*/
                break;
            }
        }

        //  if (!foundMatch)
        //   System.out.println("-- prefix "+dxccEntity.prefix+" not found in most wanted list");
    }

    // iterate a second time and resolve the very specific ones
    // usually we don't get a match on the first iteration because of small differences like
    // DXCC -> 5V , most wanted -> 5V7
    //
    // so in this iteration we check all the unresolved and check sub-prefixes

    //System.out.println("Matching DXCC list to most wanted...PASS 2");
    for (DXCCEntity dxccEntity : _dxccList) {
        if (dxccEntity.rankingInMostWanted != 0)
            continue;

        boolean foundMatch = false;
        for (DXCCEntity wantedEntity : _mostWantedList) {
            if (StringUtils.startsWithIgnoreCase(StringUtils.remove(wantedEntity.prefix, '/'),
                    StringUtils.remove(dxccEntity.prefix, '/'))) {
                dxccEntity.rankingInMostWanted = wantedEntity.rankingInMostWanted;

                matchedWantedDxccCount++;
                foundMatch = true;
                break;
            }
        }

        // if (!foundMatch)
        //   System.out.println("-- prefix "+dxccEntity.prefix+" not found in most wanted list");
    }

    //System.out.println("* Checked "+dxccListCount+" DXCC entities across "+wantedDxccCount+" most wanted and found "+matchedWantedDxccCount+" matches");
}

From source file:xbdd.webapp.rest.BasicAuthFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    final HttpServletResponse httpResponse = (HttpServletResponse) response;

    if (httpRequest.getUserPrincipal() == null) {
        final String basicAuth = httpRequest.getHeader(AUTHORIZATION_HEADER);

        if (basicAuth != null && StringUtils.startsWithIgnoreCase(basicAuth, BASIC_PREFIX)) {
            final String usernamePassword = new String(
                    Base64.decodeBase64(basicAuth.substring(BASIC_PREFIX.length()).trim()), "UTF-8");
            final String[] args = usernamePassword.split(BASIC_AUTH_SEPARATOR, 2);
            httpRequest.login(args[0], args[1]);
        } else {/*from w  w w . ja v  a2s .  com*/
            httpRequest.authenticate(httpResponse);
            return;
        }
    }

    filterChain.doFilter(request, response);
}