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.krawler.common.util.SchedulingUtilities.java

public static Date calculateEndDate(Date sDate, String duration, int[] NonWorkDays, String[] CmpHoliDays,
        String userid) throws ParseException, ServiceException {
    Date dt = new Date();
    java.text.SimpleDateFormat sdfLong = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String edate = "";
    Calendar c = Calendar.getInstance();
    dt = sDate;/*from   ww  w  .j av  a 2  s .c  o  m*/
    double d = getDurationInDays(duration);
    c.setTime(dt);
    if (d > 0) {
        c.add(Calendar.DATE, (int) (d - 1));
    } else {
        c.add(Calendar.DATE, (int) d);
    }
    Date nDate = dt;
    int flag = 0;
    int nwd = nonWorkingDays(nDate, c.getTime(), NonWorkDays, CmpHoliDays);
    while (nwd != 0) {
        nDate = c.getTime();
        if (nwd == 1 && flag == 0) {
            c.add(Calendar.DATE, nwd);
            flag = 1;
        } else {
            c.add(Calendar.DATE, nwd - 1);
        }
        nwd = nonWorkingDays(nDate, c.getTime(), NonWorkDays, CmpHoliDays);
    }
    dt = c.getTime();
    edate = sdfLong.format(dt);
    if (Arrays.binarySearch(NonWorkDays, (c.get(Calendar.DAY_OF_WEEK) - 1)) > -1) {
        edate = getNextWorkingDay(edate, NonWorkDays, CmpHoliDays);
    }
    dt = sdfLong.parse(edate);
    return dt;
}

From source file:de.dhke.projects.cutil.collections.cow.CopyOnWriteMultiMapKeySetTest.java

/**
 * Test of iterator method, of class CopyOnWriteMultiMapKeySet.
 *//*w  w w . j  ava 2s  .  c om*/
@Test
public void testIteratorNoCopyBefore() {
    Iterator<String> iter = _keySet.iterator();
    String[] referenceArray = { "1", "2", "3" };
    Arrays.sort(referenceArray);
    for (int i = 0; i < _keySet.size(); ++i) {
        assertTrue(iter.hasNext());
        assertTrue(Arrays.binarySearch(referenceArray, iter.next()) >= 0);
    }
    assertFalse(iter.hasNext());

    // _cowMap.copy();
    iter = _keySet.iterator();
    String first = iter.next();
    iter.remove();
    assertFalse(_cowMap.containsKey(first));
}

From source file:ch.algotrader.future.FutureSymbol.java

/**
 * Converts from future year symbol to year ordinal number from  {@code 0} to {@code 9}
 * @param year future year symbol// w  ww  .  j  av  a2s . c  o  m
 * @return value from {@code 0} to {@code 9} in case of a successful symbol conversion,
 *  {@code -1} if case of a failure.
 */
public static int convertYear(final String year) {
    return Arrays.binarySearch(yearEnc, year);
}

From source file:io.getlime.security.powerauth.app.server.service.PowerAuthServiceImpl.java

@Override
public GetErrorCodeListResponse getErrorCodeList(GetErrorCodeListRequest request) throws Exception {
    String language = request.getLanguage();
    // Check if the language is valid ISO language, use EN as default
    if (Arrays.binarySearch(Locale.getISOLanguages(), language) < 0) {
        language = Locale.ENGLISH.getLanguage();
    }//from   w  w  w  .j av a2  s  . c  om
    Locale locale = new Locale(language);
    GetErrorCodeListResponse response = new GetErrorCodeListResponse();
    List<String> errorCodeList = ServiceError.allCodes();
    for (String errorCode : errorCodeList) {
        GetErrorCodeListResponse.Errors error = new GetErrorCodeListResponse.Errors();
        error.setCode(errorCode);
        error.setValue(localizationProvider.getLocalizedErrorMessage(errorCode, locale));
        response.getErrors().add(error);
    }
    return response;
}

From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.crossover.CrossOverOperator.java

protected int[] getCrossPoints(boolean initEnd, int nPoints, int max) {

    int[] points;
    int point, i, maxPoints;

    if (max - 1 == nPoints) {
        points = new int[max + 1];
        for (i = 0; i <= max; i++) {
            points[i] = i;/*from  w w  w  .j  av a  2 s.c  o m*/
        }
        return points;
    }

    if (initEnd) {

        points = new int[nPoints + 2];
        Arrays.fill(points, Integer.MAX_VALUE);
        points[0] = 0;
        i = 1;
        maxPoints = points.length - 1;

    } else {

        points = new int[nPoints];
        Arrays.fill(points, Integer.MAX_VALUE);
        i = 0;
        maxPoints = points.length;
    }

    while (i < maxPoints) {

        point = (int) Math.round(EAFRandom.nextDouble() * (max - 2));
        if (Arrays.binarySearch(points, point) < 0) {

            points[i] = point;
            i++;
            Arrays.sort(points);
        }

    }

    if (initEnd) {
        points[points.length - 1] = max;
    }

    return points;

}

From source file:net.sf.firemox.token.Register.java

/**
 * Return null of enum value corresponding to the given Xsd name.
 * //from  w ww  . ja  va 2 s  . c  om
 * @param xsdName
 *          the Xsd name of this Register.
 * @return null of enum value corresponding to the given Xsd name.
 */
public static Register valueOfXsd(String xsdName) {
    TestOn on = TestOn.valueOfXsd(xsdName);
    if (on != null) {
        return new Register(on);
    }
    final int index = Arrays.binarySearch(REGISTER_NAMES, xsdName);
    if (index >= 0)
        return Register.deserialize(REGISTER_VALUES[index]);
    return null;
}

From source file:com.playonlinux.wine.WinePrefix.java

private boolean checkSearchExcludedFiles(String candidateName) {
    return (Arrays.binarySearch(SEARCH_EXCLUDED_EXECUTABLE, candidateName) == 0);
}

From source file:Spline2D.java

/**
 * Returns an interpolated value./* w ww .j a v  a2s  .c om*/
 * @param x
 * @return the interpolated value
 */
public double getValue(double x) {
    if (xx.length == 0) {
        return Double.NaN;
    }

    if (xx.length == 1) {
        if (xx[0] == x) {
            return yy[0];
        } else {
            return Double.NaN;
        }
    }

    int index = Arrays.binarySearch(xx, x);
    if (index > 0) {
        return yy[index];
    }

    index = -(index + 1) - 1;
    //TODO linear interpolation or extrapolation
    if (index < 0) {
        return yy[0];
    }

    return a[index] + b[index] * (x - xx[index]) + c[index] * Math.pow(x - xx[index], 2)
            + d[index] * Math.pow(x - xx[index], 3);
}

From source file:org.catrobat.catroid.pocketmusic.ui.TrackView.java

public void clearColorGridColumn(int column) {
    column = columnSanityCheck(column);/*ww  w.  j  a  va  2 s.c o  m*/

    for (int i = 0; i < ROW_COUNT; i++) {
        boolean isBlackRow = Arrays.binarySearch(BLACK_KEY_INDICES, i) > -1;
        int noteColorId;
        if (isBlackRow) {
            noteColorId = R.color.light_grey;
        } else {
            noteColorId = R.color.white;
        }
        trackRowViews.get(i).getChildAt(column)
                .setBackgroundColor(ContextCompat.getColor(getContext(), noteColorId));
    }
}

From source file:index.partition.ZCurvePartitioner.java

public int overlapPartition(double x, double y) {
    long zValue = computeZ(mbr, x, y);
    int partition = Arrays.binarySearch(zSplits, zValue);
    if (partition < 0)
        partition = -partition - 1;/*from  w w  w .  j  a va2  s  .  c  o m*/
    return partition;
}