Example usage for org.apache.commons.lang ArrayUtils isEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isEmpty.

Prototype

public static boolean isEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is empty or null.

Usage

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

public void conceptRefactor() {
    String sourceOutlineUri;/*  w w  w .j  a  v  a2s.c o m*/
    String sourceConceptUri;

    if (MindRaider.profile.getActiveOutlineUri() == null) {
        JOptionPane.showMessageDialog(OutlineJPanel.this,
                Messages.getString("NotebookOutlineJPanel.toRefactorConceptTheNotebookMustBeOpened"),
                Messages.getString("NotebookOutlineJPanel.refactoringError"), JOptionPane.ERROR_MESSAGE);
        return;
    }

    DefaultMutableTreeNode node = getSelectedTreeNode();
    if (node != null) {
        if (node.isLeaf()) {
            try {
                if (JOptionPane.showConfirmDialog(MindRaider.mainJFrame,
                        Messages.getString("NotebookOutlineJPanel.doYouWantToRefactorConcept", node.toString()),
                        Messages.getString("NotebookOutlineJPanel.refactorConcept"),
                        JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                    return;
                }

                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                sourceOutlineUri = MindRaider.outlineCustodian.getActiveOutlineResource().resource.getMetadata()
                        .getUri().toString();
                sourceConceptUri = ((OutlineNode) node).getUri();
                MindRaider.noteCustodian.discard(sourceOutlineUri, ((OutlineNode) parent).getUri(),
                        sourceConceptUri);
                ConceptResource conceptResource = MindRaider.noteCustodian.get(sourceOutlineUri,
                        sourceConceptUri);

                // choose target outline and create new concept into this notebook
                new OpenOutlineJDialog(Messages.getString("NotebookOutlineJPanel.refactorConcept"),
                        Messages.getString("NotebookOutlineJPanel.selectTargetNotebook"),
                        Messages.getString("NotebookOutlineJPanel.refactor"), false);

                // create that concept in the target notebook (put it to the root)
                String targetConceptUri = conceptResource.resource.getMetadata().getUri().toString();
                while (MindRaiderConstants.EXISTS.equals(
                        MindRaider.noteCustodian.create(MindRaider.outlineCustodian.getActiveOutlineResource(),
                                null, conceptResource.getLabel(), targetConceptUri,
                                conceptResource.getAnnotation(), false))) {
                    targetConceptUri += "_";
                }
                // refactor also attachments
                AttachmentProperty[] attachments = conceptResource.getAttachments();
                if (!ArrayUtils.isEmpty(attachments)) {
                    ConceptResource newConceptResource = MindRaider.noteCustodian
                            .get(MindRaider.outlineCustodian.getActiveOutlineResource().resource.getMetadata()
                                    .getUri().toString(), targetConceptUri);
                    for (AttachmentProperty attachment : attachments) {
                        newConceptResource.addAttachment(attachment.getDescription(), attachment.getUrl());
                    }
                    newConceptResource.save();
                }

                // delete discarded concept in the source outline
                MindRaider.noteCustodian.deleteConcept(sourceOutlineUri, sourceConceptUri);

                refresh();
                MindRaider.spidersGraph.selectNodeByUri(sourceOutlineUri);
                MindRaider.spidersGraph.renderModel();
            } catch (Exception e1) {
                logger.debug(Messages.getString("NotebookOutlineJPanel.unableToRefactorConcept"), e1);
                StatusBar.show(Messages.getString("NotebookOutlineJPanel.unableToRefactorConcept"));
            }
        } else {
            StatusBar.show(Messages.getString("NotebookOutlineJPanel.discardingingOnlyLeafConcepts"));
            JOptionPane.showMessageDialog(OutlineJPanel.this,
                    Messages.getString("NotebookOutlineJPanel.refactoringOnlyLeafConcepts"),
                    Messages.getString("NotebookOutlineJPanel.refactoringError"), JOptionPane.ERROR_MESSAGE);
            return;
        }
    } else {
        logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected"));
    }

}

From source file:com.photon.phresco.util.Utility.java

public static File getPomFileLocation(String appDirPath, String module) throws PhrescoException {
    try {//from  ww w.  j av a 2s.com
        File[] split_phresco = null;
        File[] dotPhrescoFolders = null;
        File dotAppDir = null;
        File srcAppDir = null;
        File pomFile = null;
        ProjectInfo projectInfo = getProjectInfo(appDirPath, module);
        if (projectInfo == null) {
            return pomFile;
        }
        ApplicationInfo appInfo = projectInfo.getAppInfos().get(0);

        File appDir = new File(appDirPath);
        String name = appDir.getName();

        String[] split = appDirPath.split("###");
        if (split.length > 1) {
            for (int i = 0; i < split.length;) {
                appDir = new File(split[0]);
                name = split[1];
                break;
            }
        }

        if (StringUtils.isNotEmpty(module)) {
            File appDirT = new File(appDir + File.separator + module);
            dotPhrescoFolders = appDirT.listFiles(new PhrescoFileNameFilter(DOT_PHRESCO_FOLDER));
        } else {
            dotPhrescoFolders = appDir.listFiles(new PhrescoFileNameFilter(DOT_PHRESCO_FOLDER));
        }

        if (!ArrayUtils.isEmpty(dotPhrescoFolders)) {
            File parentFile = dotPhrescoFolders[0].getParentFile();
            pomFile = new File(parentFile + File.separator + appInfo.getPhrescoPomFile());
            if (pomFile.exists()) {
                return pomFile;
            }
            pomFile = new File(parentFile + File.separator + appInfo.getPomFile());
            if (pomFile.exists()) {
                return pomFile;
            }
        }

        if (ArrayUtils.isEmpty(dotPhrescoFolders)) {
            dotAppDir = new File(appDir + File.separator + name + SUFFIX_PHRESCO);
            if (StringUtils.isNotEmpty(module)) {
                dotAppDir = new File(dotAppDir.getPath() + File.separator + module);
            }
            split_phresco = dotAppDir.listFiles(new PhrescoFileNameFilter(DOT_PHRESCO_FOLDER));

            if (!ArrayUtils.isEmpty(split_phresco)) {
                File parentFile = split_phresco[0].getParentFile();
                pomFile = new File(parentFile + File.separator + appInfo.getPhrescoPomFile());
                if (pomFile.exists()) {
                    return pomFile;
                }
                pomFile = new File(parentFile + File.separator + appInfo.getPomFile());
                if (pomFile.exists()) {
                    return pomFile;
                }
            } else {
                dotAppDir = new File(appDir + File.separator + name);
                if (StringUtils.isNotEmpty(module)) {
                    dotAppDir = new File(dotAppDir.getPath() + File.separator + module);
                }
                split_phresco = dotAppDir.listFiles(new PhrescoFileNameFilter(DOT_PHRESCO_FOLDER));

                if (!ArrayUtils.isEmpty(split_phresco)) {
                    File parentFile = split_phresco[0].getParentFile();
                    pomFile = new File(parentFile + File.separator + appInfo.getPhrescoPomFile());
                    if (pomFile.exists()) {
                        return pomFile;
                    }
                    pomFile = new File(parentFile + File.separator + appInfo.getPomFile());
                    if (pomFile.exists()) {
                        return pomFile;
                    }
                }
            }

            if (!pomFile.exists()) {
                if (StringUtils.isNotEmpty(module)) {
                    srcAppDir = new File(appDir + File.separator + name + File.separator + module);
                } else {
                    srcAppDir = new File(appDir + File.separator + name);
                }
                pomFile = new File(srcAppDir + File.separator + appInfo.getPhrescoPomFile());
                if (pomFile.exists()) {
                    return pomFile;
                }
                pomFile = new File(srcAppDir + File.separator + appInfo.getPomFile());
                if (pomFile.exists()) {
                    return pomFile;
                }
            }
        }

    } catch (JsonSyntaxException e) {
        throw new PhrescoException(e);
    } catch (JsonIOException e) {
        throw new PhrescoException(e);
    }
    return null;

}

From source file:com.photon.phresco.framework.impl.ProjectAdministratorImpl.java

private void fillProjects(File[] dotProjectFiles, List<Project> projects) throws PhrescoException {

    S_LOGGER.debug(//  ww w  .  j  a  v  a2s .c o m
            "Entering Method ProjectAdministratorImpl.fillProjects(File[] dotProjectFiles, List<Project> projects)");

    if (ArrayUtils.isEmpty(dotProjectFiles)) {
        return;
    }

    Gson gson = new Gson();
    BufferedReader reader = null;

    for (File dotProjectFile : dotProjectFiles) {
        try {
            reader = new BufferedReader(new FileReader(dotProjectFile));
            ProjectInfo projectInfo = gson.fromJson(reader, ProjectInfo.class);
            projects.add(new ProjectImpl(projectInfo));
        } catch (FileNotFoundException e) {
            throw new PhrescoException(e);
        } finally {
            Utility.closeStream(reader);
        }
    }
}

From source file:edu.jhuapl.openessence.controller.ReportController.java

private GraphObject createGraph(OeDataSource dataSource, final String userPrincipalName,
        final Collection<Record> records, final Dimension dimension, final Dimension filter,
        final Dimension accumulation, DefaultGraphData data, ChartModel chart, List<Filter> filters) {

    String filterId = (filter == null) ? dimension.getId() : filter.getId();
    Map<String, String> possibleKeyValueMap = null;
    if (dimension.getPossibleValuesConfiguration() != null
            && dimension.getPossibleValuesConfiguration().getData() != null) {
        List<List<Object>> dataMap = dimension.getPossibleValuesConfiguration().getData();
        possibleKeyValueMap = new HashMap<String, String>();
        for (int i = 0; i < dataMap.size(); i++) {
            String dispVal = dataMap.get(i).size() == 2 ? dataMap.get(i).get(1).toString()
                    : dataMap.get(i).get(0).toString();
            possibleKeyValueMap.put(dataMap.get(i).get(0).toString(), dispVal);
        }/*from w  w w  . ja v a2s.c  om*/
    }

    GraphDataSerializeToDiskHandler hndl = new GraphDataSerializeToDiskHandler(graphDir);
    GraphObject graph = null;

    Color[] colorsFromHex = null;
    //only set an array if they provided one
    if (!ArrayUtils.isEmpty(chart.getGraphBaseColors())) {
        colorsFromHex = ControllerUtils.getColorsFromHex(Color.BLUE, chart.getGraphBaseColors());
        //TODO when we limit the series these colors need augmented.  Create a map of id = graphbasecolor[index] first, then use that map to create a
        //new graph base color array that combines the parameter list with the default list...
        data.setGraphBaseColors(colorsFromHex);
    }

    GraphController gc = getGraphController(null, hndl, userPrincipalName);

    List<Record> recs = new ArrayList<Record>(records);

    String otherLabel = messageSource.getDataSourceMessage("graph.category.other", dataSource);

    LinkedHashMap<String, ChartData> recordMap = getRecordMap(recs, accumulation.getId(), dimension.getId(),
            filterId);
    //perform series limit
    recordMap = ControllerUtils.getSortedAndLimitedChartDataMap(recordMap, chart.getCategoryLimit(),
            otherLabel);

    //if there is no data (all zeros for a pie chart) the chart will not display anything
    if (!ControllerUtils.isCollectionValued(getCountsForChart(recordMap)) && !chart.isShowNoDataGraph()) {
        //this will hide the title and message if there is no data
        data.setGraphTitle("");
        data.setNoDataMessage("");
    }

    // Create urls for each slice/bar
    DataSeriesSource dss = null;
    StringBuilder jsCall = new StringBuilder();
    jsCall.append("javascript:OE.report.datasource.showDetails({");

    if (dataSource instanceof DataSeriesSource) {
        dss = (DataSeriesSource) dataSource;

        Collection<Dimension> dims = new ArrayList<Dimension>(dss.getResultDimensions());
        Collection<String> dimIds = ControllerUtils.getDimensionIdsFromCollection(dims);

        Collection<Dimension> accums = new ArrayList<Dimension>(dss.getAccumulations());

        for (Dimension d : accums) {
            if (dimIds.contains(d.getId()) && d.getId().equals(accumulation.getId())) {

            } else {
                dimIds.remove(d.getId());
            }
        }

        jsCall.append("dsId:'").append(dss.getClass().getName()).append("'");
        //specify results
        jsCall.append(",results:[").append(StringUtils.collectionToDelimitedString(dimIds, ",", "'", "'"))
                .append(']');
        //specify accumId
        jsCall.append(",accumId:'").append(accumulation.getId()).append("'");

        addJavaScriptFilters(jsCall, filters, dimension.getId());
    }

    int rSize = recordMap.size();
    int aSize = 1;
    String[] lbl = new String[rSize];
    String[][] txtb = new String[1][rSize];
    double[][] bardat = new double[aSize][rSize];
    String[][] txtp = new String[rSize][1];
    double[][] piedat = new double[rSize][aSize];
    String[][] urlsP = new String[rSize][1];
    String[][] urlsB = new String[1][rSize];
    int i = 0;
    double totalCount = 0;
    DecimalFormat df = new DecimalFormat("#.##");

    for (String key : recordMap.keySet()) {
        if (recordMap.get(key) != null && recordMap.get(key).getCount() != null
                && !recordMap.get(key).getCount().isNaN()) {
            totalCount += recordMap.get(key).getCount();
        }
    }

    for (String key : recordMap.keySet()) {
        Double dubVal = recordMap.get(key).getCount();
        String strPercentVal = df.format(100 * dubVal / totalCount);
        lbl[i] = recordMap.get(key).getName();
        //create bar data set
        bardat[0][i] = dubVal;
        txtb[0][i] = lbl[i] + " - " + Double.toString(dubVal) + " (" + strPercentVal + "%)";
        if (lbl[i].length() > DEFAULT_LABEL_LENGTH) {
            lbl[i] = lbl[i].substring(0, DEFAULT_LABEL_LENGTH - 3) + "...";
        }
        //create pie data set
        piedat[i][0] = dubVal;
        txtp[i][0] = lbl[i] + " - " + Double.toString(dubVal) + " (" + strPercentVal + "%)";
        if (lbl[i].length() > DEFAULT_LABEL_LENGTH) {
            lbl[i] = lbl[i].substring(0, DEFAULT_LABEL_LENGTH - 3) + "...";
        }
        //TODO all "Others" to return details of all results except for those in recordMap.keyset
        //We need a "Not" filter
        if (!otherLabel.equals(key)) {
            if (dataSource instanceof DataSeriesSource) {
                if (dimension.getId().equals(filterId) && possibleKeyValueMap != null) {
                    if (possibleKeyValueMap.containsKey(key)) {
                        urlsP[i][0] = jsCall.toString() + "," + filterId + ":'" + key + "'" + "});";
                        urlsB[0][i] = jsCall.toString() + "," + filterId + ":'" + key + "'" + "});";
                    } else {
                        urlsP[i][0] = jsCall.toString() + "});";
                        urlsB[0][i] = jsCall.toString() + "});";
                    }
                } else {
                    if (key == null || key.equals("")
                            || key.equals(messageSource.getMessage("graph.dimension.null", "Empty Value"))) {
                        // TODO: This is when we have an ID field also marked as isResult:true and the value is null
                        // We can not provide url param filterId:null as field can be numeric and we get a java.lang.NumberFormatException...
                        urlsP[i][0] = jsCall.toString() + "});";
                        urlsB[0][i] = jsCall.toString() + "});";
                    } else {
                        urlsP[i][0] = jsCall.toString() + "," + filterId + ":'" + key + "'" + "});";
                        urlsB[0][i] = jsCall.toString() + "," + filterId + ":'" + key + "'" + "});";
                    }
                }
            }
        }

        i++;
    }

    if (BAR.equalsIgnoreCase(chart.getType())) {
        data.setCounts(bardat);
        data.setXLabels(lbl);
        data.setMaxLabeledCategoryTicks(rSize);
        data.setAltTexts(txtb);
        if (jsCall.length() > 0) {
            data.setLineSetURLs(urlsB);
        }
        //TODO add encoding?
        graph = gc.createBarGraph(data, false, true);
    } else if (PIE.equalsIgnoreCase(chart.getType())) {
        data.setCounts(piedat);
        data.setLineSetLabels(lbl);
        data.setAltTexts(txtp);
        if (jsCall.length() > 0) {
            data.setLineSetURLs(urlsP);
        }
        graph = gc.createPieGraph(data, Encoding.PNG_WITH_TRANSPARENCY);
    }
    return graph;
}

From source file:gnete.card.service.impl.MerchServiceImpl.java

/**
 * ? ?//from   w  w w .  j ava2 s . com
 */
private List<Pair<Terminal, Integer>> buildTermsFromFile(File file) throws BizException {
    List<String> lines = null;
    try {
        lines = IOUtil.readLines(file, DEFAULT_ENCODING);
        Assert.isTrue(lines.size() >= 2 && lines.size() <= 101, "?100?");
    } catch (IOException e) {
        logger.warn(e, e);
        throw new BizException("???");
    }

    List<Pair<Terminal, Integer>> termList = new ArrayList<Pair<Terminal, Integer>>(lines.size() - 1);
    int termTotalCnt = 0;// 
    for (int i = 1; i < lines.size(); i++) {
        String errMsgPrefix = String.format("%s", i);
        String detailLine = (String) lines.get(i);
        Assert.isTrue(!StringUtils.isBlank(detailLine), errMsgPrefix + "??");

        String[] lineArr = detailLine.split(",", -1);
        Assert.isTrue(!ArrayUtils.isEmpty(lineArr), errMsgPrefix + "??");
        Assert.isTrue(lineArr.length == 8, errMsgPrefix + "8");

        Integer termCnt = Integer.valueOf(lineArr[7].trim());
        termTotalCnt = termTotalCnt + termCnt;
        Assert.isTrue(termTotalCnt <= 1000, "???1000?");

        Terminal term = new Terminal();
        term.setMerchId(lineArr[0].trim());
        term.setManageBranch(lineArr[1].trim());
        term.setMaintenance(lineArr[2].trim());
        term.setMerchAddress(lineArr[3].trim());
        term.setPosContact(lineArr[4].trim());
        term.setPosContactPhone(lineArr[5].trim());
        term.setEntryMode(lineArr[6].trim());

        Assert.notBlank(term.getMerchId(), errMsgPrefix + "??");
        Assert.isTrue(this.merchInfoDAO.isExist(term.getMerchId()),
                errMsgPrefix + "?[" + term.getMerchId() + "]");

        Assert.notTrue(
                StringUtils.isNotEmpty(term.getManageBranch())
                        && !this.branchInfoDAO.isExist(term.getManageBranch()),
                errMsgPrefix + "?[" + term.getManageBranch() + "]");

        Assert.notBlank(term.getMaintenance(), errMsgPrefix + "?");
        Assert.notTrue(
                StringUtils.isNotEmpty(term.getMaintenance())
                        && !this.branchInfoDAO.isExist(term.getMaintenance()),
                errMsgPrefix + "?[" + term.getMaintenance() + "]");

        Assert.isTrue(Arrays.asList("0", "1").contains(term.getEntryMode()),
                errMsgPrefix + "?01");

        termList.add(new MutablePair<Terminal, Integer>(term, termCnt));
    }
    return termList;
}

From source file:com.test.stringtest.StringUtils.java

/**
 * <p>Search a String to find the first index of any
 * character in the given set of characters.</p>
 *
 * <p>A <code>null</code> String will return <code>-1</code>.
 * A <code>null</code> or zero length search array will return <code>-1</code>.</p>
 *
 * <pre>// ww w  .  j a va 2s . c o  m
 * StringUtils.indexOfAny(null, *)                = -1
 * StringUtils.indexOfAny("", *)                  = -1
 * StringUtils.indexOfAny(*, null)                = -1
 * StringUtils.indexOfAny(*, [])                  = -1
 * StringUtils.indexOfAny("zzabyycdxx",['z','a']) = 0
 * StringUtils.indexOfAny("zzabyycdxx",['b','y']) = 3
 * StringUtils.indexOfAny("aba", ['z'])           = -1
 * </pre>
 *
 * @param str  the String to check, may be null
 * @param searchChars  the chars to search for, may be null
 * @return the index of any of the chars, -1 if no match or null input
 * @since 2.0
 */
public static int indexOfAny(String str, char[] searchChars) {
    if (isEmpty(str) || ArrayUtils.isEmpty(searchChars)) {
        return -1;
    }
    for (int i = 0; i < str.length(); i++) {
        char ch = str.charAt(i);
        for (int j = 0; j < searchChars.length; j++) {
            if (searchChars[j] == ch) {
                return i;
            }
        }
    }
    return -1;
}

From source file:com.test.stringtest.StringUtils.java

/**
 * <p>Search a String to find the first index of any
 * character not in the given set of characters.</p>
 *
 * <p>A <code>null</code> String will return <code>-1</code>.
 * A <code>null</code> or zero length search array will return <code>-1</code>.</p>
 *
 * <pre>/*  w  w w .j av a2 s  .c o  m*/
 * StringUtils.indexOfAnyBut(null, *)           = -1
 * StringUtils.indexOfAnyBut("", *)             = -1
 * StringUtils.indexOfAnyBut(*, null)           = -1
 * StringUtils.indexOfAnyBut(*, [])             = -1
 * StringUtils.indexOfAnyBut("zzabyycdxx",'za') = 3
 * StringUtils.indexOfAnyBut("zzabyycdxx", '')  = 0
 * StringUtils.indexOfAnyBut("aba", 'ab')       = -1
 * </pre>
 *
 * @param str  the String to check, may be null
 * @param searchChars  the chars to search for, may be null
 * @return the index of any of the chars, -1 if no match or null input
 * @since 2.0
 */
public static int indexOfAnyBut(String str, char[] searchChars) {
    if (isEmpty(str) || ArrayUtils.isEmpty(searchChars)) {
        return -1;
    }
    outer: for (int i = 0; i < str.length(); i++) {
        char ch = str.charAt(i);
        for (int j = 0; j < searchChars.length; j++) {
            if (searchChars[j] == ch) {
                continue outer;
            }
        }
        return i;
    }
    return -1;
}

From source file:jef.tools.StringUtils.java

/**
 * /*from  www. j  a va  2  s .co m*/
 * 
 * @param str
 * @param searchChars
 * @param startPos
 * @return
 */
public static int indexOfAny(String str, char[] searchChars, int startPos) {
    if (isEmpty(str) || ArrayUtils.isEmpty(searchChars)) {
        return -1;
    }
    for (int i = startPos; i < str.length(); i++) {
        char ch = str.charAt(i);
        for (int j = 0; j < searchChars.length; j++) {
            if (searchChars[j] == ch) {
                return i;
            }
        }
    }
    return -1;
}

From source file:com.yucheng.cmis.pub.util.NewArrayUtils.java

/**
 * <p>Finds the index of the given value in the array starting at the given index.</p>
 *
 * <p>This method returns {@link #INDEX_NOT_FOUND} (<code>-1</code>) for a <code>null</code> input array.</p>
 *
 * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 * length will return {@link #INDEX_NOT_FOUND} (<code>-1</code>).</p>
 * /*from w  ww  . j  ava2s.  c  o  m*/
 * @param array  the array to search through for the object, may be <code>null</code>
 * @param valueToFind  the value to find
 * @param startIndex  the index to start searching at
 * @return the index of the value within the array,
 *  {@link #INDEX_NOT_FOUND} (<code>-1</code>) if not found or <code>null</code> array input
 */
public static int indexOf(double[] array, double valueToFind, int startIndex) {
    if (ArrayUtils.isEmpty(array)) {
        return INDEX_NOT_FOUND;
    }
    if (startIndex < 0) {
        startIndex = 0;
    }
    for (int i = startIndex; i < array.length; i++) {
        if (valueToFind == array[i]) {
            return i;
        }
    }
    return INDEX_NOT_FOUND;
}

From source file:com.yucheng.cmis.pub.util.NewArrayUtils.java

/**
 * <p>Finds the index of the given value in the array starting at the given index.
 * This method will return the index of the first value which falls between the region
 * defined by valueToFind - tolerance and valueToFind + tolerance.</p>
 *
 * <p>This method returns {@link #INDEX_NOT_FOUND} (<code>-1</code>) for a <code>null</code> input array.</p>
 *
 * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 * length will return {@link #INDEX_NOT_FOUND} (<code>-1</code>).</p>
 * //from w  w  w .  j av  a 2 s.c o m
 * @param array  the array to search through for the object, may be <code>null</code>
 * @param valueToFind  the value to find
 * @param startIndex  the index to start searching at
 * @param tolerance tolerance of the search
 * @return the index of the value within the array,
 *  {@link #INDEX_NOT_FOUND} (<code>-1</code>) if not found or <code>null</code> array input
 */
public static int indexOf(double[] array, double valueToFind, int startIndex, double tolerance) {
    if (ArrayUtils.isEmpty(array)) {
        return INDEX_NOT_FOUND;
    }
    if (startIndex < 0) {
        startIndex = 0;
    }
    double min = valueToFind - tolerance;
    double max = valueToFind + tolerance;
    for (int i = startIndex; i < array.length; i++) {
        if (array[i] >= min && array[i] <= max) {
            return i;
        }
    }
    return INDEX_NOT_FOUND;
}