Example usage for java.util Arrays binarySearch

List of usage examples for java.util Arrays binarySearch

Introduction

In this page you can find the example usage for java.util Arrays binarySearch.

Prototype

public static int binarySearch(Object[] a, Object key) 

Source Link

Document

Searches the specified array for the specified object using the binary search algorithm.

Usage

From source file:com.gordoni.opal.TriInterpolator.java

public double value(double[] p) {
    double x = p[0];
    x = Math.max(x, mp.floor[0]);
    x = Math.min(x, mp.ceiling[0]);
    double y = p[1];
    y = Math.max(y, mp.floor[1]);
    y = Math.min(y, mp.ceiling[1]);
    double z = p[2];
    z = Math.max(z, mp.floor[2]);
    z = Math.min(z, mp.ceiling[2]);
    double v = f.value(x, y, z);
    int xindex = Arrays.binarySearch(xval, x);
    if (xindex < 0)
        xindex = -xindex - 2;/*from www  . j  a va 2  s  .  co  m*/
    int yindex = Arrays.binarySearch(yval, y);
    if (yindex < 0)
        yindex = -yindex - 2;
    int zindex = Arrays.binarySearch(zval, z);
    if (zindex < 0)
        zindex = -zindex - 2;
    double fmin = fval[xindex][yindex][zindex];
    double fmax = fval[xindex][yindex][zindex];
    if (xindex + 1 < xval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex][zindex]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex][zindex]);
    }
    if (yindex + 1 < yval.length) {
        fmin = Math.min(fmin, fval[xindex][yindex + 1][zindex]);
        fmax = Math.max(fmax, fval[xindex][yindex + 1][zindex]);
    }
    if (zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex][yindex][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex][yindex][zindex + 1]);
    }
    if (xindex + 1 < xval.length && yindex + 1 < yval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex + 1][zindex]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex + 1][zindex]);
    }
    if (xindex + 1 < xval.length && zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex][zindex + 1]);
    }
    if (yindex + 1 < yval.length && zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex][yindex + 1][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex][yindex + 1][zindex + 1]);
    }
    if (xindex + 1 < xval.length && yindex + 1 < yval.length && zindex + 1 < zval.length) {
        fmin = Math.min(fmin, fval[xindex + 1][yindex + 1][zindex + 1]);
        fmax = Math.max(fmax, fval[xindex + 1][yindex + 1][zindex + 1]);
    }
    v = Math.max(v, fmin);
    v = Math.min(v, fmax);
    return v;
}

From source file:de.tap.easy_xkcd.utils.Comic.java

public Comic(Integer number, Context context) throws IOException {
    if (number != 0) {
        jsonUrl = "https://xkcd.com/" + number.toString() + "/info.0.json";
    } else {/*from  w w  w.java2s .  co  m*/
        jsonUrl = "https://xkcd.com/info.0.json";
    }
    try {
        comicData = loadComicData(jsonUrl);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    if (context != null) {
        if (Arrays.binarySearch(context.getResources().getIntArray(R.array.interactive_comics),
                comicNumber) >= 0) { //Check for interactive comic
            comicData[0] = comicData[0] + " " + context.getResources().getString(R.string.title_interactive);
        }

        int i = Arrays.binarySearch(context.getResources().getIntArray(R.array.large_comics), comicNumber);
        if (i >= 0 && PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pref_large", true)) { //Check for large comic
            comicData[2] = context.getResources().getStringArray(R.array.large_comics_urls)[i];
        }
    }
}

From source file:io.cloudslang.content.httpclient.build.RequestBuilder.java

public HttpRequestBase build() {
    if (method == null) {
        throw new IllegalArgumentException(
                "The 'method' input is required. Provide one of " + Arrays.asList(methods).toString());
    }//from  w ww. j a v  a 2 s .  c om
    String method = this.method.toUpperCase().trim();
    if (Arrays.binarySearch(methods, method) < 0) {
        throw new IllegalArgumentException("invalid '" + HttpClientInputs.METHOD + "' input '" + method + "'");
    }

    org.apache.http.client.methods.RequestBuilder requestBuilder = org.apache.http.client.methods.RequestBuilder
            .create(method);
    requestBuilder.setUri(uri);
    requestBuilder.setEntity(entity);

    return (HttpRequestBase) requestBuilder.build();
}

From source file:Util.java

public static final int find(double[] array, double valueToFind) {
    return Arrays.binarySearch(array, valueToFind);
}

From source file:org.diorite.utils.validator.string.StringAllowedCharsValidatorImpl.java

@Override
public boolean validate(final String s) {
    if (s == null) {
        return false;
    }// w  w w  .  j a  v a  2s .  co  m
    for (final char c : s.toCharArray()) {
        if (Arrays.binarySearch(this.chars, c) < 0) {
            return false;
        }
    }
    return true;
}

From source file:org.diorite.utils.validator.string.StringDisallowedCharsValidatorImpl.java

@Override
public boolean validate(final String s) {
    if (s == null) {
        return false;
    }/* ww w. j av a  2s  . c o m*/
    for (final char c : s.toCharArray()) {
        if (Arrays.binarySearch(this.chars, c) >= 0) {
            return false;
        }
    }
    return true;
}

From source file:com.buddycloud.mediaserver.business.util.ImageUtils.java

public static boolean isImage(String extension) {
    return Arrays.binarySearch(FORMATS, extension.toLowerCase()) >= 0;
}

From source file:com.adguard.commons.utils.ReservedDomains.java

/**
 * Checks if domain name is reserved// w  ww . j  a v  a 2  s  .  com
 *
 * @param domainName Domain name
 * @return true if reserved
 */
public static boolean isReservedDomainName(String domainName) {
    if (reservedDomainNames == null) {
        initialize();
    }

    return Arrays.binarySearch(reservedDomainNames, domainName) >= 0;
}

From source file:com.pureinfo.srm.reports.table.data.pinggu.ParameterSetAction.java

/**
 * @see com.pureinfo.ark.interaction.ActionBase#executeAction()
 *///  ww w  . j a v a  2s. c  o  m
public ActionForward executeAction() throws PureException {
    tempOrgCode = request.getRequiredParameter("tempOrgCode", "code");
    propFileName = ClassResourceUtil.mapFullPath(propFileName, true);

    Properties prop = new Properties();
    InputStream iFile = null;
    FileOutputStream oFile = null;
    try {
        iFile = new FileInputStream(propFileName);
        prop.load(iFile);

        String codeInSystem = prop.getProperty("parameter.org.code");
        if (StringUtils.isEmpty(codeInSystem)) {
            codeInSystem = tempOrgCode;
        } else {
            String[] codeArr = codeInSystem.split(",");
            Arrays.sort(codeArr);
            int index = Arrays.binarySearch(codeArr, tempOrgCode);
            if (index < 0) {
                codeInSystem += "," + tempOrgCode;
            }
        }
        prop.setProperty("parameter.org.code", codeInSystem);

        Enumeration e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            if (!name.startsWith("para.")) {
                continue;
            }
            String value = request.getParameter(name);

            if (StringUtils.isEmpty(value)) {
                logger.debug("the value of " + name.substring(5) + " is empty.SKIP.");
                continue;
            }

            value = value.trim();

            logger.debug("to set property:" + name.substring(5) + "with[" + value + "]");

            prop.setProperty(name.substring(5), value);
        }

        oFile = new FileOutputStream(propFileName, false);

        prop.store(oFile, "parameter for pinggu");

        // to reload properties.
        PureSystem.shutdown();

    } catch (Exception ex) {
        throw new PureException(0, "", ex);
    } finally {
        try {
            if (iFile != null)
                iFile.close();
            if (oFile != null)
                oFile.close();
            prop.clear();
        } catch (IOException e) {
            e.printStackTrace(System.err);
        }

    }

    return mapping.findForward("success");
}

From source file:net.sf.jooreports.templates.TemplatePreProcessor.java

public void process(OpenDocumentArchive archive) throws DocumentTemplateException, IOException {
    for (Iterator it = archive.getEntryNames().iterator(); it.hasNext();) {
        String entryName = (String) it.next();
        if (Arrays.binarySearch(xmlEntries, entryName) >= 0) {
            InputStream inputStream = archive.getEntryInputStream(entryName);
            OutputStream outputStream = archive.getEntryOutputStream(entryName);
            applyXmlFilters(inputStream, outputStream);
            inputStream.close();/*w  w  w .j  a v a2  s.  co m*/
            outputStream.close();
        }
    }
}