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.bt.download.android.gui.transfers.PeerHttpDownload.java

public static String cleanFileName(String badFileName) {

    StringBuilder cleanName = new StringBuilder();
    for (int i = 0; i < badFileName.length(); i++) {
        int c = (int) badFileName.charAt(i);
        if (Arrays.binarySearch(illegalChars, c) < 0) {
            cleanName.append((char) c);
        }//from w w  w  .  j a  v  a2 s . c  om
    }
    return cleanName.toString();
}

From source file:com.opengamma.util.timeseries.fast.integer.object.FastArrayIntObjectTimeSeries.java

public T getDataPointFast(final int time) {
    final int index = Arrays.binarySearch(_times, time);
    if (index >= 0) {
        return _values[index];
    } else {/*from   w w w  .  ja  v  a2s  . c  om*/
        throw new NoSuchElementException();
    }
}

From source file:com.liferay.portlet.documentlibrary.util.PDFProcessorImpl.java

public boolean isSupported(String mimeType) {
    if (Validator.isNull(mimeType)) {
        return false;
    }/*w  w  w .  java 2  s  . c o  m*/

    if (mimeType.equals(ContentTypes.APPLICATION_PDF) || mimeType.equals(ContentTypes.APPLICATION_X_PDF)) {

        return true;
    }

    if (DocumentConversionUtil.isEnabled()) {
        Set<String> extensions = MimeTypesUtil.getExtensions(mimeType);

        for (String extension : extensions) {
            extension = extension.substring(1);

            String[] targetExtensions = DocumentConversionUtil.getConversions(extension);

            if (Arrays.binarySearch(targetExtensions, "pdf") >= 0) {
                return true;
            }
        }
    }

    return false;
}

From source file:dk.dma.ais.packet.AisPacketFiltersStateful.java

/**
 * Return false if this message is known to be related to a target with a ship type outside the given list.
 *///from   ww w  .j  a v  a  2 s .c o  m

public Predicate<AisPacket> filterOnTargetShiptype(Integer[] shiptypes) {
    final int[] list = ArrayUtils.toPrimitive(shiptypes);
    Arrays.sort(list);
    return new Predicate<AisPacket>() {
        public boolean test(AisPacket p) {
            aisPacketStream.add(p); // Update state
            final int mmsi = getMmsi(p); // Get MMSI in question
            final int shiptype = getShiptype(mmsi); // Extract shiptype no. - if we know it
            return shiptype < 0 ? false : Arrays.binarySearch(list, shiptype) >= 0;
        }

        public String toString() {
            return "shiptype in " + skipBrackets(Arrays.toString(list));
        }
    };
}

From source file:com.opengamma.analytics.financial.model.finitedifference.PDEGrid1D.java

private int getLowerBoundIndex(final double[] array, final double t) {
    final int n = array.length;
    if (t < array[0]) {
        return 0;
    }//from  w w w .j ava 2 s.c  o m
    if (t > array[n - 1]) {
        return n - 1;
    }

    int index = Arrays.binarySearch(array, t);
    if (index >= 0) {
        // Fast break out if it's an exact match.
        return index;
    }
    if (index < 0) {
        index = -(index + 1);
        index--;
    }
    return index;
}

From source file:com.opengamma.util.timeseries.fast.longint.object.FastArrayLongObjectTimeSeries.java

public T getDataPointFast(final long time) {
    final int index = Arrays.binarySearch(_times, time);
    if (index >= 0) {
        return _values[index];
    } else {//from w  w  w .ja v a2  s .  c  om
        throw new NoSuchElementException();
    }
}

From source file:com.abstratt.mdd.frontend.textuml.renderer.TextUMLRenderingUtils.java

private static String escapeIdentifierIfNeeded(String identifier) {
    if (StringUtils.isBlank(identifier))
        return "";
    if (!StringUtils.isAlpha(identifier)) {
        StringBuffer result = new StringBuffer(identifier.length());
        char[] chars = identifier.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] != '_'
                    && ((Character.isDigit(chars[i]) && i == 0) || !Character.isLetterOrDigit(chars[i])))
                result.append('\\');
            result.append(chars[i]);/*from   w ww. j a  v a2  s . com*/
        }
        return result.toString();
    }
    if (Arrays.binarySearch(TextUMLConstants.KEYWORDS, identifier) >= 0)
        return "\\" + identifier;
    return identifier;
}

From source file:com.puppycrawl.tools.checkstyle.XmlTreeWalker.java

/**
 * Register a check for a given configuration.
 * @param aCheck the check to register/*w ww.j  a va  2  s . c o m*/
 * @throws CheckstyleException if an error occurs
 */
private void registerCheck(Check aCheck) throws CheckstyleException {
    final int[] tokens;
    final Set<String> checkTokens = aCheck.getTokenNames();
    if (!checkTokens.isEmpty()) {
        tokens = aCheck.getRequiredTokens();

        //register configured tokens
        final int acceptableTokens[] = aCheck.getAcceptableTokens();
        Arrays.sort(acceptableTokens);
        for (String token : checkTokens) {
            try {
                final int tokenId = TokenTypes.getTokenId(token);
                if (Arrays.binarySearch(acceptableTokens, tokenId) >= 0) {
                    registerCheck(token, aCheck);
                }
                // TODO: else log warning
            } catch (final IllegalArgumentException ex) {
                throw new CheckstyleException("illegal token \"" + token + "\" in check " + aCheck, ex);
            }
        }
    } else {
        tokens = aCheck.getDefaultTokens();
    }
    for (int element : tokens) {
        registerCheck(element, aCheck);
    }
    mAllChecks.add(aCheck);
}

From source file:com.opengamma.util.timeseries.fast.longint.FastArrayLongDoubleTimeSeries.java

public double getDataPointFast(final long time) {
    final int index = Arrays.binarySearch(_times, time);
    if (index >= 0) {
        return _values[index];
    } else {/*from w  w  w .jav a  2 s  .  co m*/
        throw new NoSuchElementException();
    }
}

From source file:com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck.java

/**
 * Checks whether AcceptableTokens contains the given ast.
 * @param ast the token to check.//from  w ww .  j  av  a2 s.co  m
 * @return true if the ast is in AcceptableTokens.
 */
private boolean isAcceptableToken(DetailAST ast) {
    boolean result = false;
    if (Arrays.binarySearch(acceptableTokens, ast.getType()) >= 0) {
        result = true;
    }
    return result;
}