List of usage examples for java.util BitSet BitSet
public BitSet()
From source file:org.apache.hama.bsp.message.io.PreFetchCache.java
public PreFetchCache(int numBuffers, long totalMessages, int capacity) { this.objectListArr = new Object[numBuffers]; this.totalMessages = totalMessages; this.bufferBitSet = new BitSet(); status = new SpilledDataReadStatus(numBuffers, bufferBitSet); for (int i = 0; i < numBuffers; ++i) { this.objectListArr[i] = new ArrayList<M>(capacity); }/*w w w. ja v a2 s . c o m*/ this.capacity = capacity; }
From source file:mastodon.algorithms.SABisectionAlgorithm.java
protected void tryPruning() { //choose the number of species in list to perturb based on a Poisson distributions with rate equal to variable "mean" above int numberToSet = 0; int numberToClear = 0; while (numberToSet < 1 || numberToSet > currPrunedSpeciesCount) { numberToSet = pd.sample() + 1;/*from w ww . ja v a 2 s . c o m*/ } if (numberToSet > (bts.getTaxaCount() - currPrunedSpeciesCount)) { numberToSet = bts.getTaxaCount() - currPrunedSpeciesCount; } numberToClear = numberToSet; BitSet bitsToSet = new BitSet(); BitSet bitsToClear = new BitSet(); for (int e = 0; e < numberToSet; e++) { int choice = 0; while (true) { choice = (int) (Random.nextDouble() * bts.getTaxaCount()); if (!currPruning.get(choice) && !bitsToSet.get(choice)) { break; } } bitsToSet.set(choice); } for (int e = 0; e < numberToClear; e++) { int choice = 0; while (true) { choice = (int) (Random.nextDouble() * bts.getTaxaCount()); if (currPruning.get(choice) && !bitsToClear.get(choice)) { break; } } bitsToClear.set(choice); } currPruning.or(bitsToSet); currPruning.xor(bitsToClear); currScore = bts.pruneFast(currPruning); bts.unPrune(); }
From source file:org.lockss.servlet.DaemonStatus.java
/** * Handle a request//from ww w . jav a 2 s . co m * @throws IOException */ public void lockssHandleRequest() throws IOException { if (!StringUtil.isNullString(req.getParameter("isDaemonReady"))) { if (pluginMgr.areAusStarted()) { resp.setStatus(200); PrintWriter wrtr = resp.getWriter(); resp.setContentType("text/plain"); wrtr.println("true"); } else { PrintWriter wrtr = resp.getWriter(); resp.setContentType("text/plain"); wrtr.println("false"); resp.sendError(202, "Not ready"); } return; } outputFmt = OUTPUT_HTML; // default output is html String outputParam = req.getParameter("output"); if (!StringUtil.isNullString(outputParam)) { if ("html".equalsIgnoreCase(outputParam)) { outputFmt = OUTPUT_HTML; } else if ("xml".equalsIgnoreCase(outputParam)) { outputFmt = OUTPUT_XML; } else if ("text".equalsIgnoreCase(outputParam)) { outputFmt = OUTPUT_TEXT; } else if ("csv".equalsIgnoreCase(outputParam)) { outputFmt = OUTPUT_CSV; } else { log.warning("Unknown output format: " + outputParam); } } String optionsParam = req.getParameter("options"); tableOptions = new BitSet(); if (isDebugUser()) { log.debug2("Debug user. Setting OPTION_DEBUG_USER"); tableOptions.set(StatusTable.OPTION_DEBUG_USER); } for (Iterator iter = StringUtil.breakAt(optionsParam, ',').iterator(); iter.hasNext();) { String s = (String) iter.next(); if ("norows".equalsIgnoreCase(s)) { tableOptions.set(StatusTable.OPTION_NO_ROWS); } } tableName = req.getParameter("table"); tableKey = req.getParameter("key"); if (StringUtil.isNullString(tableName)) { tableName = statSvc.getDefaultTableName(); } if (StringUtil.isNullString(tableKey)) { tableKey = null; } sortKey = req.getParameter("sort"); if (StringUtil.isNullString(sortKey)) { sortKey = null; } switch (outputFmt) { case OUTPUT_HTML: doHtmlStatusTable(); break; case OUTPUT_XML: try { doXmlStatusTable(); } catch (XmlDomBuilder.XmlDomException xde) { throw new IOException("Error building XML", xde); } break; case OUTPUT_TEXT: doTextStatusTable(); break; case OUTPUT_CSV: doCsvStatusTable(); break; } }
From source file:ezbake.deployer.impl.Files.java
public static int convertPosixFilePermissionsToTarArchiveEntryMode(Set<PosixFilePermission> permissions) { BitSet mode = new BitSet(); if (permissions.contains(PosixFilePermission.OTHERS_EXECUTE)) { mode.set(PosixFilePermission.OTHERS_EXECUTE.ordinal()); }//from w w w . jav a 2 s . c o m if (permissions.contains(PosixFilePermission.OTHERS_WRITE)) { mode.set(PosixFilePermission.OTHERS_WRITE.ordinal()); } if (permissions.contains(PosixFilePermission.OTHERS_READ)) { mode.set(PosixFilePermission.OTHERS_READ.ordinal()); } if (permissions.contains(PosixFilePermission.GROUP_EXECUTE)) { mode.set(PosixFilePermission.GROUP_EXECUTE.ordinal()); } if (permissions.contains(PosixFilePermission.GROUP_WRITE)) { mode.set(PosixFilePermission.GROUP_WRITE.ordinal()); } if (permissions.contains(PosixFilePermission.GROUP_READ)) { mode.set(PosixFilePermission.GROUP_READ.ordinal()); } if (permissions.contains(PosixFilePermission.OWNER_EXECUTE)) { mode.set(PosixFilePermission.OWNER_EXECUTE.ordinal()); } if (permissions.contains(PosixFilePermission.OWNER_WRITE)) { mode.set(PosixFilePermission.OWNER_WRITE.ordinal()); } if (permissions.contains(PosixFilePermission.OWNER_READ)) { mode.set(PosixFilePermission.OWNER_READ.ordinal()); } return (int) mode.toLongArray()[0]; }
From source file:io.viewserver.operators.group.GroupByOperator.java
@Override protected void processConfig(IGroupByConfig config) { if (configChanged(config)) { List<String> groupBy = config.getGroupBy(); if (groupIdComponents == null || groupIdComponents.length < groupBy.size()) { groupIdComponents = new int[groupBy.size()]; }// www . j av a2 s.c o m this.groupBy = groupBy.toArray(new String[groupBy.size()]); input.groupByColumns = new ColumnHolder[this.groupBy.length]; List<IGroupByConfig.Summary> summaries = config.getSummaries(); this.summaryConfig = summaries.toArray(new IGroupByConfig.Summary[summaries.size()]); this.countColumnName = config.getCountColumnName(); subtotals.clear(); if (config.getSubtotals() != null && config.getSubtotals().size() != 0) { for (String subtotal : config.getSubtotals()) { BitSet subtotalColumns = new BitSet(); if (subtotal != null && !"".equals(subtotal)) { for (String subtotalColumn : subtotal.split("\\|")) { int index = groupBy.indexOf(subtotalColumn); if (index == -1) { throw new IllegalArgumentException( "Invalid subtotal configuration - no group column '" + subtotalColumn + "'"); } subtotalColumns.set(index); } } subtotals.add(subtotalColumns); } } else { BitSet subtotalColumns = new BitSet(); for (int i = 0; i < groupBy.size(); i++) { subtotalColumns.set(i); } subtotals.add(subtotalColumns); } input.resetSchema(); } }
From source file:au.org.ala.delta.intkey.WriteOnceIntkeyItemsFile.java
public void writeAttributeBits(int charNumber, List<BitSet> attributes, int numBits) { int record = updateCharacterIndex(charNumber); // Merge the list into a single BitSet. BitSet master = new BitSet(); int offset = 0; for (BitSet set : attributes) { for (int i = 0; i < numBits; i++) { if (set.get(i)) { master.set(i + offset);//from ww w . j av a 2 s . c o m } } offset += numBits; } List<Integer> values = bitSetToInts(master, numBits * attributes.size()); writeToRecord(record, values); }
From source file:org.apache.tez.dag.utils.JavaProfilerOptions.java
/** * Get the set of tasks to be profiled within a vertex * * @param tasksToProfileInVertex/* w w w . j av a 2 s .c o m*/ * @return Set<Integer> containing the task indexes to be profiled */ private BitSet parseTasksToProfile(String tasksToProfileInVertex) { BitSet profiledTaskSet = new BitSet(); if (Strings.isNullOrEmpty(tasksToProfileInVertex)) { return profiledTaskSet; } Iterable<String> tasksInVertex = Splitter.on(",").omitEmptyStrings().trimResults() .split(tasksToProfileInVertex); for (String task : tasksInVertex) { /** * TODO: this is horrible way to check the ranges. * Should use RangeSet when guava is upgraded. Also, need to support partial * ranges like "1:", ":50". With current implementation partial ranges are not * allowed. */ if (task.endsWith(":") || task.startsWith(":")) { //invalid range. e.g :20, 6: are not supported. LOG.warn("Partial range is considered as an invalid option"); return null; } Matcher taskMatcher = RANGE_REGEX.matcher(task); if (taskMatcher.find()) { int start = Integer.parseInt((taskMatcher.group(1).trim())); int end = Integer.parseInt((taskMatcher.group(2).trim())); for (int i = Math.min(start, end); i <= Math.max(start, end); i++) { profiledTaskSet.set(i); } } else { profiledTaskSet.set(Integer.parseInt(task.trim())); } } return profiledTaskSet; }
From source file:org.apache.tez.dag.app.dag.impl.DAGSchedulerNaturalOrderControlled.java
private void taskAttemptSeen(String vertexName, TezTaskAttemptID taskAttemptID) { BitSet scheduledTasks = vertexScheduledTasks.get(vertexName); if (scheduledTasks == null) { scheduledTasks = new BitSet(); vertexScheduledTasks.put(vertexName, scheduledTasks); }//from w w w. j a v a 2 s .c o m if (taskAttemptID != null) { // null for 0 task vertices scheduledTasks.set(taskAttemptID.getTaskID().getId()); } }
From source file:org.apache.jackrabbit.core.query.lucene.CachingIndexReader.java
private BitSet initShareableNodes(IndexReader delegatee) throws IOException { BitSet shareableNodes = new BitSet(); TermDocs tDocs = delegatee.termDocs(new Term(FieldNames.SHAREABLE_NODE, "")); try {/*from www. j av a 2 s . co m*/ while (tDocs.next()) { shareableNodes.set(tDocs.doc()); } } finally { tDocs.close(); } return shareableNodes; }
From source file:org.lockss.servlet.AddContent.java
/** * Handle a request/*from w w w .j a va2 s. c o m*/ * * @throws java.io.IOException */ public void lockssHandleRequest() throws IOException { if (!StringUtil.isNullString(req.getParameter("isDaemonReady"))) { if (pluginMgr.areAusStarted()) { resp.setStatus(200); PrintWriter wrtr = resp.getWriter(); resp.setContentType("text/plain"); wrtr.println("true"); } else { PrintWriter wrtr = resp.getWriter(); resp.setContentType("text/plain"); wrtr.println("false"); resp.sendError(202, "Not ready"); } return; } if (StringUtil.isNullString(action)) { try { getMultiPartRequest(); if (multiReq != null) { action = multiReq.getString(ACTION_TAG); } } catch (FormDataTooLongException e) { errMsg = "Uploaded file too large: " + e.getMessage(); // leave action null, will call displayAuSummary() below } } session = getSession(); outputFmt = OUTPUT_HTML; // default output is html String outputParam = req.getParameter("output"); if (!StringUtil.isNullString(outputParam)) { if ("html".equalsIgnoreCase(outputParam)) { outputFmt = OUTPUT_HTML; } else { log.warning("Unknown output format: " + outputParam); } } String optionsParam = req.getParameter("options"); tableOptions = new BitSet(); if (isDebugUser()) { log.debug2("Debug user. Setting OPTION_DEBUG_USER"); tableOptions.set(StatusTable.OPTION_DEBUG_USER); } for (String s : StringUtil.breakAt(optionsParam, ',')) { if ("norows".equalsIgnoreCase(s)) { tableOptions.set(StatusTable.OPTION_NO_ROWS); } } tableName = req.getParameter("table"); tableKey = req.getParameter("key"); if (StringUtil.isNullString(tableName)) { tableName = "AuOverview"; } if (StringUtil.isNullString(tableKey)) { tableKey = null; } sortKey = req.getParameter("sort"); if (StringUtil.isNullString(sortKey)) { sortKey = null; } groupKey = req.getParameter("group"); if (StringUtil.isNullString(groupKey)) { groupKey = "publisher"; } type = req.getParameter("type"); if (StringUtil.isNullString(type)) { type = ""; } typeKey = req.getParameter("type"); String auStartString = req.getParameter("start"); if (auStartString == null) { auStart = 'a'; } else { auStart = auStartString.charAt(0); } String auEndString = req.getParameter("end"); if (auEndString == null) { auEnd = 'a'; } else { auEnd = auEndString.charAt(0); } filterKey = req.getParameter("filter"); if (StringUtil.isNullString(filterKey)) { filterKey = ""; } timeKey = req.getParameter("timeKey"); if (StringUtil.isNullString(timeKey)) { timeKey = ""; } tabKey = req.getParameter("tab"); switch (outputFmt) { case OUTPUT_HTML: doHtmlStatusTable(); break; } actionMessage = null; if ("Delete selected".equals(req.getParameter("deleteSubmit"))) { String[] deleteAUs = req.getParameterValues("au"); if (deleteAUs != null) { List<String> aus = Arrays.asList(deleteAUs); log.error("AUs: " + aus); doRemoveAus(aus); actionMessage = createActionMessage(aus, false); } else { log.error("No AUs selected"); actionMessage = "No AUs selected!"; } } if ("Add selected".equals(req.getParameter("addSubmit"))) { String[] addAUs = req.getParameterValues("au"); if (addAUs != null) { List<String> aus = Arrays.asList(addAUs); log.error("AUs: " + aus); doAddAus(RemoteApi.BATCH_ADD_ADD, aus); actionMessage = createActionMessage(aus, true); } else { log.error("No AUs selected"); actionMessage = "No AUs selected!"; } } if (actionMessage != null) { session.setAttribute("actionMessage", actionMessage); } String publisher = req.getParameter("deletePublisher"); if (!StringUtil.isNullString(publisher)) { deletePublisher(publisher); } }