List of usage examples for java.util BitSet get
public boolean get(int bitIndex)
From source file:org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager.java
@Override public void onSourceTaskCompleted(String srcVertexName, Integer srcTaskId) { updateSourceTaskCount();/*w w w .ja va2s.c o m*/ SourceVertexInfo srcInfo = srcVertexInfo.get(srcVertexName); if (srcInfo.edgeProperty.getDataMovementType() == DataMovementType.SCATTER_GATHER) { //handle duplicate events for bipartite sources BitSet completedSourceTasks = srcInfo.finishedTaskSet; if (completedSourceTasks != null) { // duplicate notifications tracking if (!completedSourceTasks.get(srcTaskId)) { completedSourceTasks.set(srcTaskId); // source task has completed ++numBipartiteSourceTasksCompleted; } } } schedulePendingTasks(); }
From source file:org.caleydo.data.importer.tcga.FirehoseProvider.java
private TCGAFileInfo filterColumns(TCGAFileInfo full, Pair<TCGAFileInfo, Boolean> sampled) { File in = full.getFile();/*from w w w . j a v a2 s .c o m*/ File out = new File(in.getParentFile(), "F" + in.getName()); TCGAFileInfo r = new TCGAFileInfo(out, full.getArchiveURL(), full.getSourceFileName()); if (out.exists() && !settings.isCleanCache()) return r; assert full != null; if (sampled == null || sampled.getFirst() == null) { log.severe("can't filter the full gene file: " + in + " - sampled not found"); return full; } // full: 1row, 2col // sampled: 3row, 3col Set<String> good = readGoodSamples(sampled.getFirst().getFile()); if (good == null) return full; try (BufferedReader fin = new BufferedReader(new FileReader(in)); PrintWriter w = new PrintWriter(out)) { String[] header = fin.readLine().split("\t"); BitSet bad = filterCols(header, good); { StringBuilder b = new StringBuilder(); for (int i = bad.nextSetBit(0); i >= 0; i = bad.nextSetBit(i + 1)) b.append(' ').append(header[i]); log.warning("remove bad samples of " + in + ":" + b); } w.append(header[0]); for (int i = 1; i < header.length; ++i) { if (bad.get(i)) continue; w.append('\t').append(header[i]); } String line; while ((line = fin.readLine()) != null) { w.println(); int t = line.indexOf('\t'); w.append(line.subSequence(0, t)); int prev = t; int i = 1; for (t = line.indexOf('\t', t + 1); t >= 0; t = line.indexOf('\t', t + 1), ++i) { if (!bad.get(i)) w.append(line.subSequence(prev, t)); prev = t; } if (!bad.get(i)) w.append(line.subSequence(prev, line.length())); } } catch (IOException e) { log.log(Level.SEVERE, "can't filter full file: " + in, e); } return r; }
From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java
private void writeBits(final DataOutput header, final BitSet bits, final int length) throws IOException { int cache = 0; int shift = 7; for (int i = 0; i < length; i++) { cache |= ((bits.get(i) ? 1 : 0) << shift); if (--shift < 0) { header.write(cache);/* w w w . j ava 2s. co m*/ shift = 7; cache = 0; } } if (shift != 7) { header.write(cache); } }
From source file:org.apache.hadoop.mapreduce.lib.input.TestKeyValueTextInputFormat.java
public void testFormat() throws Exception { Job job = new Job(defaultConf); Path file = new Path(workDir, "test.txt"); int seed = new Random().nextInt(); LOG.info("seed = " + seed); Random random = new Random(seed); localFs.delete(workDir, true);// ww w. ja v a 2 s . c om FileInputFormat.setInputPaths(job, workDir); // for a variety of lengths for (int length = 0; length < MAX_LENGTH; length += random.nextInt(MAX_LENGTH / 10) + 1) { LOG.debug("creating; entries = " + length); // create a file with length entries Writer writer = new OutputStreamWriter(localFs.create(file)); try { for (int i = 0; i < length; i++) { writer.write(Integer.toString(i * 2)); writer.write("\t"); writer.write(Integer.toString(i)); writer.write("\n"); } } finally { writer.close(); } KeyValueTextInputFormat format = new KeyValueTextInputFormat(); JobContext jobContext = new JobContext(job.getConfiguration(), new JobID()); List<InputSplit> splits = format.getSplits(jobContext); LOG.debug("splitting: got = " + splits.size()); TaskAttemptContext context = new TaskAttemptContext(job.getConfiguration(), new TaskAttemptID()); // check each split BitSet bits = new BitSet(length); for (InputSplit split : splits) { LOG.debug("split= " + split); RecordReader<Text, Text> reader = format.createRecordReader(split, context); Class readerClass = reader.getClass(); assertEquals("reader class is KeyValueLineRecordReader.", KeyValueLineRecordReader.class, readerClass); reader.initialize(split, context); try { int count = 0; while (reader.nextKeyValue()) { int v = Integer.parseInt(reader.getCurrentValue().toString()); LOG.debug("read " + v); if (bits.get(v)) { LOG.warn("conflict with " + v + " in split " + split + " at " + reader.getProgress()); } assertFalse("Key in multiple partitions.", bits.get(v)); bits.set(v); count++; } LOG.debug("split=" + split + " count=" + count); } finally { reader.close(); } } assertEquals("Some keys in no partition.", length, bits.cardinality()); } }
From source file:asterix.parser.classad.ClassAdParser.java
public static int checkNullConstraints(ARecordType recType, BitSet nulls) { boolean isNull = false; for (int i = 0; i < recType.getFieldTypes().length; i++) { if (nulls.get(i) == false) { IAType type = recType.getFieldTypes()[i]; if (type.getTypeTag() != ATypeTag.NULL && type.getTypeTag() != ATypeTag.UNION) { return i; }/* w w w. j a v a 2 s . c o m*/ if (type.getTypeTag() == ATypeTag.UNION) { // union List<IAType> unionList = ((AUnionType) type).getUnionList(); for (int j = 0; j < unionList.size(); j++) { if (unionList.get(j).getTypeTag() == ATypeTag.NULL) { isNull = true; break; } } if (!isNull) { return i; } } } } return -1; }
From source file:bin.spider.frame.uri.UURIFactory.java
/** * Ensure that there all characters needing escaping * in the passed-in String are escaped. Stray '%' characters * are *not* escaped, as per browser behavior. * // w w w .jav a2s . c om * @param u String to escape * @param charset * @param bitset * @return string with any necessary escaping applied */ private String ensureMinimalEscaping(String u, final String charset, final BitSet bitset) { if (u == null) { return null; } for (int i = 0; i < u.length(); i++) { char c = u.charAt(i); if (!bitset.get(c)) { try { u = LaxURLCodec.DEFAULT.encode(bitset, u, charset); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } break; } } return u; }
From source file:org.apache.hadoop.mapred.TestMultiFileInputFormat.java
public void testFormat() throws IOException { if (LOG.isInfoEnabled()) { LOG.info("Test started"); LOG.info("Max split count = " + MAX_SPLIT_COUNT); LOG.info("Split count increment = " + SPLIT_COUNT_INCR); LOG.info("Max bytes per file = " + MAX_BYTES); LOG.info("Max number of files = " + MAX_NUM_FILES); LOG.info("Number of files increment = " + NUM_FILES_INCR); }/* ww w . j a v a2s . c o m*/ MultiFileInputFormat<Text, Text> format = new DummyMultiFileInputFormat(); FileSystem fs = FileSystem.getLocal(job); for (int numFiles = 1; numFiles < MAX_NUM_FILES; numFiles += (NUM_FILES_INCR / 2) + rand.nextInt(NUM_FILES_INCR / 2)) { Path dir = initFiles(fs, numFiles, -1); BitSet bits = new BitSet(numFiles); for (int i = 1; i < MAX_SPLIT_COUNT; i += rand.nextInt(SPLIT_COUNT_INCR) + 1) { LOG.info("Running for Num Files=" + numFiles + ", split count=" + i); MultiFileSplit[] splits = (MultiFileSplit[]) format.getSplits(job, i); bits.clear(); for (MultiFileSplit split : splits) { long splitLength = 0; for (Path p : split.getPaths()) { long length = fs.getContentSummary(p).getLength(); assertEquals(length, lengths.get(p.getName()).longValue()); splitLength += length; String name = p.getName(); int index = Integer.parseInt(name.substring(name.lastIndexOf("file_") + 5)); assertFalse(bits.get(index)); bits.set(index); } assertEquals(splitLength, split.getLength()); } } assertEquals(bits.cardinality(), numFiles); fs.delete(dir, true); } LOG.info("Test Finished"); }
From source file:org.caleydo.core.util.impute.KNNImpute.java
/** * split the neighbor hood in two groups based on 2 k-means * * @param neighborhood//from ww w . ja v a2 s . c o m * @return */ private Pair<List<Gene>, List<Gene>> twoMeanClusterSplit(List<Gene> neighborhood) { final int n = neighborhood.size(); final int maxit = desc.getMaxit(); final double eps = desc.getEps(); int a_start = r.nextInt(n); int b_start = r.nextInt(n); Gene a_center = new Gene(1, -1, Arrays.copyOf(neighborhood.get(a_start).data, samples)); Gene b_center = new Gene(1, -1, Arrays.copyOf(neighborhood.get(b_start).data, samples)); float[] a_center_pong = new float[samples]; Arrays.fill(a_center_pong, Float.NaN); float[] b_center_pong = new float[samples]; Arrays.fill(b_center_pong, Float.NaN); float[] tmp; BitSet partOf_a = new BitSet(n); double d_old = 0; for (int i = 0; i < maxit; ++i) { int j = 0; int changed = 0; double d_new = 0; for (Gene gene : neighborhood) { final double a_distance = distance(a_center, gene); final double b_distance = distance(b_center, gene); final boolean in_a = a_distance < b_distance; if (partOf_a.get(j) != in_a) { changed++; partOf_a.set(j, in_a); } d_new += in_a ? a_distance : b_distance; tmp = in_a ? a_center_pong : b_center_pong; // shift new center for (int k = 0; k < samples; ++k) { if (!gene.isNaN(k)) { if (Float.isNaN(tmp[k])) tmp[k] = gene.get(k); else tmp[k] += gene.get(k); } } j++; } if (changed == 0 || d_new == 0) break; final double ratio = Math.abs(d_new - d_old) / d_old; if (i > 0 && ratio < eps) break; d_old = d_new; int a_n = partOf_a.cardinality(); int b_n = n - a_n; if (a_n == 0 || b_n == 0) { // FIXME } updateCenter(a_center, a_center_pong, a_n); updateCenter(b_center, b_center_pong, b_n); } return split(neighborhood, partOf_a); }
From source file:org.wso2.andes.kernel.router.TopicRoutingMatcher.java
/** * Removing a storageQueue from the structure. * * @param storageQueue The storageQueue to remove *//*w w w . j av a 2 s . c om*/ public void removeStorageQueue(StorageQueue storageQueue) { int queueIndex = storageQueueList.indexOf(storageQueue); if (queueIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed storageQueue removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == queueIndex) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the storageQueue from storageQueue list storageQueueList.remove(queueIndex); } else { log.warn("Storage queue for with name : " + storageQueue.getName() + " is not found to " + "remove"); } }
From source file:org.wso2.andes.subscription.TopicSubscriptionBitMapStore.java
/** * Removing a subscription from the structure. * * @param subscription The subscription to remove *///from ww w. j a v a 2 s .c o m @Override public void removeSubscription(AndesSubscription subscription) { int subscriptionIndex = subscriptionList.indexOf(subscription); if (subscriptionIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed subscription removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == i) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the subscription from subscription list subscriptionList.remove(subscriptionIndex); } else { log.warn("Subscription for destination : " + subscription.getSubscribedDestination() + " is not found to " + "remove"); } }