List of usage examples for java.util Arrays binarySearch
public static int binarySearch(Object[] a, Object key)
From source file:edu.umn.cs.spatialHadoop.core.ZCurvePartitioner.java
@Override public int overlapPartition(Shape shape) { if (shape == null) return -1; Rectangle shapeMBR = shape.getMBR(); if (shapeMBR == null) return -1; // Assign to only one partition that contains the center point Point center = shapeMBR.getCenterPoint(); long zValue = computeZ(mbr, center.x, center.y); int partition = Arrays.binarySearch(zSplits, zValue); if (partition < 0) partition = -partition - 1;/*w w w. j a v a 2 s . com*/ return partition; }
From source file:com.opengamma.analytics.financial.credit.creditdefaultswap.pricing.vanilla.isdanew.ISDACompliantCurve.java
/** * The zero rate or zero hazard rate//from w ww. ja v a2s . co m * @param t Time * @return value */ public double getZeroRate(final double t) { ArgumentChecker.isTrue(t >= 0, "require t >= 0.0"); // short-cut doing binary search if (t <= _t[0]) { return _r[0]; } if (t > _t[_n - 1]) { final double rt = getRT(t, _n - 1); return rt / t; } final int index = Arrays.binarySearch(_t, t); if (index >= 0) { return _r[index]; } final int insertionPoint = -(1 + index); final double rt = getRT(t, insertionPoint); return rt / t; }
From source file:com.google.gwt.checkstyle.CustomRegexpHeaderCheck.java
/** * @param aLineNo a line number/* www .j a v a 2 s . c om*/ * @return if <code>aLineNo</code> is one of the repeat header lines. */ private boolean isMultiLine(int aLineNo) { return (Arrays.binarySearch(mMultiLines, aLineNo + 1) >= 0); }
From source file:nl.b3p.geotools.data.arcims.ArcIMSFeatureReader.java
protected SimpleFeature buildFeature(AxlFeature axlf) throws IOException { String id = null;/*from w ww . java 2s. co m*/ for (AxlField f : axlf.getFields()) { if (rowIdAttribute != null && rowIdAttribute.equals(f.getName())) { id = f.getValue(); } if (!query.retrieveAllProperties()) { if (internedPropertyNames == null) { // No properties continue; } else if (Arrays.binarySearch(internedPropertyNames, f.getName().intern()) < 0) { continue; } } Class binding = null; try { binding = featureType.getType(f.getName()).getBinding(); builder.set(f.getName(), f.getConvertedValue(binding, geometryFactory)); } catch (Exception e) { throw new IOException(String.format("Error converting field \"%s\" value \"%s\" to type %s: %s", f.getName(), f.getValue(), binding, e.toString()), e); } } return builder.buildFeature(id); }
From source file:net.devietti.ArchConfMapServlet.java
/** Fetch info for a list of conferences from WikiCFP */ private List<Conf> getConfInfo(List<String> confs) throws IOException { String query = StringUtils.join(confs, "+"); List<Conf> results = new LinkedList<Conf>(); /*/* ww w. j a v a2 s .c o m*/ * NB: year=f returns hits for this year and future years. This is exactly what we want, since * we automatically discard conferences that have already happened. */ Document doc = getURL("http://www.wikicfp.com/cfp/servlet/tool.search?year=f&q=" + query); Elements rows = doc.select("div[class=contsec] table table tr"); for (Iterator<Element> iter = rows.iterator(); iter.hasNext();) { final Element firstRow = iter.next(); final Elements confName = firstRow.select("td a"); if (confName.isEmpty()) continue; final Conf conf = new Conf(); // make sure we match one of the conferences we're interested in String cn = confName.first().text().split(" ")[0]; int found = Arrays.binarySearch(CONFERENCE_NAMES, cn); if (found < 0) continue; // not found final String confFullName = firstRow.select("td").get(1).text(); // don't match other ICS conferences, eg Information, Communication, Society if (CONFERENCE_NAMES[found].equals("ICS")) { if (!confFullName.toLowerCase().contains("supercomputing")) { continue; } } // don't match other CC conferences, eg Creative Construction if (CONFERENCE_NAMES[found].equals("CC")) { if (!confFullName.toLowerCase().contains("compiler")) { continue; } } conf.name = confName.first().text(); /* * we found a hit! The conference information is split across two <tr> table elements. * Conference name and link to cfp are in the first <tr>, and dates, location and deadline * in the second. */ final Element secondRow = iter.next(); String dates = secondRow.select("td").first().text(); String startDate = dates.substring(0, dates.indexOf('-')).trim(); conf.start = cfpDateFormat.parseDateTime(startDate); conf.end = cfpDateFormat.parseDateTime(dates.substring(dates.indexOf('-') + 1).trim()); conf.dates = cfpDateFormat.print(conf.start) + " - " + cfpDateFormat.print(conf.end); if (conf.start.year().equals(conf.end.year()) && conf.start.monthOfYear().equals(conf.end.monthOfYear())) { conf.dates = monthFormat.print(conf.start) + " " + dayFormat.print(conf.start) + "-" + dayFormat.print(conf.end) + " " + yearFormat.print(conf.start); } String deadline = secondRow.select("td").get(2).text().trim(); if (deadline.contains("(")) { // abstract deadline may be in parentheses deadline = deadline.substring(0, deadline.indexOf('(')).trim(); } conf.deadline = cfpDateFormat.parseDateTime(deadline); conf.url = "http://www.wikicfp.com" + confName.attr("href"); /* * extract the WikiCFP eventid from the link, so that, later on, the client can pull the * cfp page and get the direct conference site link. */ com.shopobot.util.URL url = new com.shopobot.util.URL(conf.url); String[] eid = url.getParameters("eventid"); if (0 == eid.length) continue; try { conf.eventid = Integer.valueOf(eid[0]); } catch (NumberFormatException e) { error("invalid event id " + eid); continue; } conf.location = secondRow.select("td").get(1).text(); results.add(conf); } return results; }
From source file:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck.java
/** * Is magic number some where at ast tree. * @param ast ast token/*from www . ja va2 s . c om*/ * @param constantDefAST constant ast * @return true if magic number is present */ private boolean isMagicNumberExists(DetailAST ast, DetailAST constantDefAST) { boolean found = false; DetailAST astNode = ast.getParent(); while (astNode != constantDefAST) { final int type = astNode.getType(); if (Arrays.binarySearch(constantWaiverParentToken, type) < 0) { found = true; break; } astNode = astNode.getParent(); } return found; }
From source file:org.apache.carbondata.core.scan.collector.impl.DictionaryBasedResultCollector.java
protected void initDimensionAndMeasureIndexesForFillingData() { List<Integer> dictionaryIndexes = new ArrayList<Integer>(); for (int i = 0; i < queryDimensions.length; i++) { if (queryDimensions[i].getDimension().hasEncoding(Encoding.DICTIONARY) || queryDimensions[i].getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) { dictionaryIndexes.add(queryDimensions[i].getDimension().getOrdinal()); }/*from w w w .ja va2 s.co m*/ } int[] primitive = ArrayUtils.toPrimitive(dictionaryIndexes.toArray(new Integer[dictionaryIndexes.size()])); Arrays.sort(primitive); actualIndexInSurrogateKey = new int[dictionaryIndexes.size()]; int index = 0; for (int i = 0; i < queryDimensions.length; i++) { if (queryDimensions[i].getDimension().hasEncoding(Encoding.DICTIONARY) || queryDimensions[i].getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY)) { actualIndexInSurrogateKey[index++] = Arrays.binarySearch(primitive, queryDimensions[i].getDimension().getOrdinal()); } } dictionaryEncodingArray = CarbonUtil.getDictionaryEncodingArray(queryDimensions); directDictionaryEncodingArray = CarbonUtil.getDirectDictionaryEncodingArray(queryDimensions); implictColumnArray = CarbonUtil.getImplicitColumnArray(queryDimensions); complexDataTypeArray = CarbonUtil.getComplexDataTypeArray(queryDimensions); order = new int[queryDimensions.length + queryMeasures.length]; for (int i = 0; i < queryDimensions.length; i++) { order[i] = queryDimensions[i].getQueryOrder(); } for (int i = 0; i < queryMeasures.length; i++) { order[i + queryDimensions.length] = queryMeasures[i].getQueryOrder(); } directDictionaryGenerators = new DirectDictionaryGenerator[queryDimensions.length]; for (int i = 0; i < queryDimensions.length; i++) { directDictionaryGenerators[i] = DirectDictionaryKeyGeneratorFactory .getDirectDictionaryGenerator(queryDimensions[i].getDimension().getDataType()); } }
From source file:fastcall.FastCallSNP.java
private void calculateVCF(ConcurrentHashMap<Integer, String> posVCFMap, List<Integer> positionList, int currentChr, int startPos, String chrSeq, int[][] depth, String[][] base) { positionList.parallelStream().forEach(position -> { int index = position - startPos; byte refBase = (byte) (chrSeq.charAt(position - 1)); int baseIndex = Arrays.binarySearch(bases, refBase); if (baseIndex < 0) { } else {/* w ww . ja v a2s . c o m*/ String vcfStr = this.getVCFString(base[index], depth[index], currentChr, position, refBase); if (vcfStr != null) { posVCFMap.put(position, this.getVCFString(base[index], depth[index], currentChr, position, refBase)); } } }); }
From source file:org.apache.http.HC4.conn.ssl.AbstractVerifier.java
private static boolean validCountryWildcard(final String parts[]) { if (parts.length != 3 || parts[2].length() != 2) { return true; // it's not an attempt to wildcard a 2TLD within a country code }/*w ww . j a v a2 s. c o m*/ return Arrays.binarySearch(BAD_COUNTRY_2LDS, parts[1]) < 0; }
From source file:jopt.csp.util.SortableIntList.java
/** * Searches the list for the specified key via {@link java.util.Arrays#binarySearch(int[], int)} * <p/>/*w w w .j a va 2 s .co m*/ * The array must be sorted (as by the sort method, above) prior to making this call. * If it is not sorted, the results are undefined. If the list contains multiple elements * with the specified value, there is no guarantee which one will be found. * * @param key the value to be searched for * @return index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1) */ public int binarySearch(int key) { trimToSize(); return Arrays.binarySearch(data, key); }