Example usage for org.apache.commons.lang3 StringUtils endsWithIgnoreCase

List of usage examples for org.apache.commons.lang3 StringUtils endsWithIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils endsWithIgnoreCase.

Prototype

public static boolean endsWithIgnoreCase(final CharSequence str, final CharSequence suffix) 

Source Link

Document

Case insensitive check if a CharSequence ends with a specified suffix.

null s are handled without exceptions.

Usage

From source file:kenh.xscript.ScriptUtils.java

public static void main(String[] args) {
    String file = null;/*  ww w  .  ja va 2  s.  c  o m*/

    for (String arg : args) {
        if (StringUtils.startsWithAny(StringUtils.lowerCase(arg), "-f:", "-file:")) {
            file = StringUtils.substringAfter(arg, ":");
        }
    }

    Element e = null;
    try {
        if (StringUtils.isBlank(file)) {

            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle("xScript");
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.setFileFilter(new FileFilter() {
                public boolean accept(File f) {
                    if (f.isDirectory()) {
                        return true;
                    } else if (f.isFile() && StringUtils.endsWithIgnoreCase(f.getName(), ".xml")) {
                        return true;
                    }
                    return false;
                }

                public String getDescription() {
                    return "xScript (*.xml)";
                }
            });

            int returnVal = chooser.showOpenDialog(null);
            chooser.requestFocus();

            if (returnVal == JFileChooser.CANCEL_OPTION)
                return;

            File f = chooser.getSelectedFile();

            e = getInstance(f, null);
        } else {
            e = getInstance(new File(file), null);
        }
        //debug(e);
        //System.out.println("----------------------");

        int result = e.invoke();
        if (result == Element.EXCEPTION) {
            Object obj = e.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION);
            if (obj != null && obj instanceof Throwable) {
                System.err.println();
                ((Throwable) obj).printStackTrace();

            } else {
                System.err.println();
                System.err.println("Unknown EXCEPTION is thrown.");
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();

        System.err.println();

        if (ex instanceof UnsupportedScriptException) {
            UnsupportedScriptException ex_ = (UnsupportedScriptException) ex;
            if (ex_.getElement() != null) {
                debug(ex_.getElement(), System.err);
            }
        }
    } finally {
        if (e != null)
            e.getEnvironment().callback();
    }
}

From source file:com.kegare.friendlymobs.util.Version.java

private static void initialize() {
    CURRENT = Optional.of(Strings.nullToEmpty(FriendlyMobs.metadata.version));
    LATEST = Optional.fromNullable(CURRENT.orNull());

    File file = FriendlyUtils.getModContainer().getSource();

    if (file != null && file.exists()) {
        if (file.isFile()) {
            if (StringUtils.endsWithIgnoreCase(FilenameUtils.getBaseName(file.getName()), "dev")) {
                DEV_DEBUG = true;/* ww w .jav a2 s  . co m*/
            }
        } else {
            DEV_DEBUG = true;
        }
    } else if (!FMLForgePlugin.RUNTIME_DEOBF) {
        DEV_DEBUG = true;
    }

    if (StringUtils.endsWithIgnoreCase(getCurrent(), "dev")) {
        DEV_DEBUG = true;
    } else if (DEV_DEBUG) {
        FriendlyMobs.metadata.version += "-dev";
    }
}

From source file:com.kegare.frozenland.util.Version.java

private static void initialize() {
    CURRENT = Optional.of(Strings.nullToEmpty(Frozenland.metadata.version));
    LATEST = Optional.fromNullable(CURRENT.orNull());

    File file = FrozenUtils.getModContainer().getSource();

    if (file != null && file.exists()) {
        if (file.isFile()) {
            String name = FilenameUtils.getBaseName(file.getName());

            if (StringUtils.endsWithIgnoreCase(name, "dev")) {
                DEV_DEBUG = true;/*from   ww w.j ava2 s.  c o  m*/
            }
        } else if (file.isDirectory()) {
            DEV_DEBUG = true;
        }
    } else if (!FMLForgePlugin.RUNTIME_DEOBF) {
        DEV_DEBUG = true;
    }

    if (Frozenland.metadata.version.endsWith("dev")) {
        DEV_DEBUG = true;
    } else if (DEV_DEBUG) {
        Frozenland.metadata.version += "-dev";
    }
}

From source file:com.kegare.caveworld.util.Version.java

private static void initialize() {
    CURRENT = Optional.of(Strings.nullToEmpty(Caveworld.metadata.version));
    LATEST = Optional.fromNullable(CURRENT.orNull());

    ModContainer mod = CaveUtils.getModContainer();
    File file = mod == null ? null : mod.getSource();

    if (file != null && file.exists()) {
        if (file.isFile()) {
            String name = FilenameUtils.getBaseName(file.getName());

            if (StringUtils.endsWithIgnoreCase(name, "dev")) {
                DEV_DEBUG = true;//from w  ww .  j  a  va 2s  .  c  o m
            }
        } else if (file.isDirectory()) {
            DEV_DEBUG = true;
        }
    } else if (!FMLForgePlugin.RUNTIME_DEOBF) {
        DEV_DEBUG = true;
    }

    if (Caveworld.metadata.version.endsWith("dev")) {
        DEV_DEBUG = true;
    } else if (DEV_DEBUG) {
        Caveworld.metadata.version += "-dev";
    }
}

From source file:kenh.expl.functions.EndsWith.java

public boolean process(String str, String suffix, boolean ignoreCase) {
    if (ignoreCase)
        return StringUtils.endsWithIgnoreCase(str, suffix);
    else/* w  w w .  jav  a 2s. c om*/
        return StringUtils.endsWith(str, suffix);
}

From source file:com.nridge.connector.fs.con_fs.core.Constants.java

public static int getCfgSleepValue(AppMgr anAppMgr, String aCfgName, int aDefaultValue) {
    int sleepInSeconds = aDefaultValue;

    String timeString = anAppMgr.getString(aCfgName);
    if (StringUtils.isNotEmpty(timeString)) {
        if (StringUtils.endsWithIgnoreCase(timeString, "m")) {
            String minuteString = StringUtils.stripEnd(timeString, "m");
            if ((StringUtils.isNotEmpty(minuteString)) && (StringUtils.isNumeric(minuteString))) {
                int minuteAmount = Integer.parseInt(minuteString);
                sleepInSeconds = minuteAmount * 60;
            }/*  w ww.ja v a2  s.co m*/
        } else if (StringUtils.endsWithIgnoreCase(timeString, "h")) {
            String hourString = StringUtils.stripEnd(timeString, "h");
            if ((StringUtils.isNotEmpty(hourString)) && (StringUtils.isNumeric(hourString))) {
                int hourAmount = Integer.parseInt(hourString);
                sleepInSeconds = hourAmount * 60 * 60;
            }
        } else if (StringUtils.endsWithIgnoreCase(timeString, "d")) {
            String dayString = StringUtils.stripEnd(timeString, "d");
            if ((StringUtils.isNotEmpty(dayString)) && (StringUtils.isNumeric(dayString))) {
                int dayAmount = Integer.parseInt(dayString);
                sleepInSeconds = dayAmount * 60 * 60 * 24;
            }
        } else // we assume seconds
        {
            String secondString = StringUtils.stripEnd(timeString, "s");
            if ((StringUtils.isNotEmpty(secondString)) && (StringUtils.isNumeric(secondString))) {
                sleepInSeconds = Integer.parseInt(secondString);
            }
        }
    }

    return sleepInSeconds;
}

From source file:AIR.Common.Utilities.Path.java

public static Collection<File> getFilesMatchingExtensions(String folder, final String[] extensions) {
    return (Collection<File>) FileUtils.listFiles(new File(folder), new IOFileFilter() {
        @Override/*from w w  w  .ja v  a 2  s  .c  o m*/
        public boolean accept(File arg0) {
            return matches(arg0.getAbsolutePath());
        }

        @Override
        public boolean accept(File arg0, String arg1) {
            return matches(arg1);
        }

        private boolean matches(String file) {
            for (int counter1 = 0; counter1 < extensions.length; ++counter1) {
                if (StringUtils.endsWithIgnoreCase(file, extensions[counter1]))
                    return true;
            }
            return false;
        }

    }, TrueFileFilter.INSTANCE);
}

From source file:com.sketchy.server.action.GetRenderedImageFiles.java

@Override
public JSONServletResult execute(HttpServletRequest request) throws Exception {
    JSONServletResult jsonServletResult = new JSONServletResult(Status.SUCCESS);
    try {/*from   www.ja  va  2s .c  om*/
        File[] files = HttpServer.IMAGE_UPLOAD_DIRECTORY.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File arg0, String filename) {
                return (StringUtils.endsWithIgnoreCase(filename, "rendered.dat"));
            }
        });

        String imageName = request.getParameter("imageName");

        List<Object> rows = new ArrayList<Object>();

        for (File file : files) {

            if (file.getName().startsWith(imageName)) {
                Map<String, Object> row = new HashMap<String, Object>();
                File dimFile = new File(file.getPath());
                if (dimFile.exists()) {
                    String json = FileUtils.readFileToString(dimFile);
                    RenderedImageAttributes renderedImageAttributes = (RenderedImageAttributes) ImageAttributes
                            .fromJson(json);
                    row.put("imageSize", Integer.toString(renderedImageAttributes.getWidth()) + " x "
                            + Integer.toString(renderedImageAttributes.getHeight()));
                    row.put("imageName", renderedImageAttributes.getImageName());
                    row.put("penWidth", renderedImageAttributes.getPenWidth());
                    row.put("filename", renderedImageAttributes.getImageFilename());
                    row.put("drawingSize", renderedImageAttributes.getDrawingSize());
                    row.put("contrast", renderedImageAttributes.getContrast());
                    row.put("brightness", renderedImageAttributes.getBrightness());
                    row.put("threshold", renderedImageAttributes.getThreshold());
                }

                rows.add(row);
            }
        }
        jsonServletResult.put("rows", rows);
    } catch (Throwable t) {
        jsonServletResult = new JSONServletResult(Status.ERROR, "Error! " + t.getMessage());
    }
    return jsonServletResult;
}

From source file:com.sketchy.server.action.GetImageFiles.java

@Override
public JSONServletResult execute(HttpServletRequest request) throws Exception {
    JSONServletResult jsonServletResult = new JSONServletResult(Status.SUCCESS);
    try {//from  w  ww  . ja  v  a  2  s.com
        File[] files = HttpServer.IMAGE_UPLOAD_DIRECTORY.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File arg0, String filename) {
                return (StringUtils.endsWithIgnoreCase(filename, ".dat")
                        && (!StringUtils.endsWithIgnoreCase(filename, "rendered.dat")));
            }
        });

        Arrays.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                if ((f1 == null) || (f2 == null))
                    return 0; // Shouldn't ever be null, but if so if either is null, then just return 0; 
                return f1.getName().compareToIgnoreCase(f2.getName());
            }
        });

        List<Object> rows = new ArrayList<Object>();
        for (File file : files) {

            Map<String, Object> row = new HashMap<String, Object>();
            File dimFile = new File(file.getPath());
            if (dimFile.exists()) {
                String json = FileUtils.readFileToString(dimFile);
                SourceImageAttributes sourceImageAttributes = (SourceImageAttributes) ImageAttributes
                        .fromJson(json);
                row.put("imageSize", Integer.toString(sourceImageAttributes.getWidth()) + " x "
                        + Integer.toString(sourceImageAttributes.getHeight()));
                row.put("imageName", sourceImageAttributes.getImageName());
                row.put("filename", sourceImageAttributes.getImageFilename());
            }

            rows.add(row);
        }

        jsonServletResult.put("rows", rows);
    } catch (Throwable t) {
        jsonServletResult = new JSONServletResult(Status.ERROR, "Error! " + t.getMessage());
    }

    return jsonServletResult;
}

From source file:com.cognifide.aet.job.common.datafilters.statuscodesfilter.StatusCodesFilter.java

protected boolean matchUrl(String paramValue, String statusCodeUrl) {
    return StringUtils.endsWithIgnoreCase(statusCodeUrl, paramValue);
}